500内部服务器错误angularjs之后/之后如何获得响应

时间:2018-09-28 13:29:44

标签: javascript angularjs http

致电邮政服务时,出现500 Internal Server Error。我确实有一个拦截器,它将打开一个对话框,尽管对话框为空。 似乎由于错误500而无法获得此调用的答案。但是我可以在chrome调试器上看到答案。尽管出现错误,如何获得响应?

我的代码:

 -interceptor:


  responseError: function (rejection) {
                var bcsAuth = $injector.get('bcsAuth');
                var MobileLoading = $injector.get('MobileLoading');
                var MobileDialog = $injector.get('MobileDialog');
 switch (rejection.status) {case 500:
                        if (rejection.statusText.toLowerCase().trim() == 'internal server error') {
                            MobileDialog.alert("error", rejection.data.message, "OK");

                        } else if (rejection.data.code && rejection.data.code == 'ETIMEDOUT') {

                            MobileDialog.alert("WARNING", "CONNECTION_TIMEOUT", "OK");
                        }

在Google chrome上调试:

enter image description here enter image description here

2 个答案:

答案 0 :(得分:1)

解决方案:答案是删除.message

并继续使用reject.data,因为它是原始文本消息,而不是json对象

MobileDialog.alert(“错误”,拒绝数据,“确定”);

答案 1 :(得分:1)

由于您将获得一个空对话框,因此将执行任何if else语句。我怀疑是reject.data.message可能为空。您需要验证服务器抛出的json的共振峰。您显示的响应是原始响应或已解析。无论哪种情况,都不会显示任何嵌套的JSON对象。对我来说这是简单的文字。

相关问题