Restangular 错误拦截器中的意外标记 u

Unexpected token u in Restangular Error Interceptor

我正在使用 Restangular 拦截器来处理状态代码为 412,409 等的错误。 但是我没有在 requestInterceptor 函数中获得状态。 我已经使用 Typescript 声明了 Restangular RequestInterceptor。

在我的 app.ts 文件中,

 app.run(Restangular){     
   Restangular.setErrorInterceptor(function(response) {//code to handle error});
            }

错误:

Restangular 提供了一个访问完整响应访问权限的选项,设置它可能会有所帮助。通过使用 Restangular.setFullResponse(true),您应该能够访问拦截器中的状态代码。

所以,我想根据你的代码片段,它现在看起来可能是这样的(因为如果你有任何其他配置部分,你正在注入 Restangular)

app.run(Restangular){
   Restangular.setFullResponse(true);     
   Restangular.setErrorInterceptor(function(response) {//code to handle error});
            }

重要的是要指出设置此选项,现在对所有服务的响应的访问将明显不同,除非您创建一些东西来处理下一个 .data 行为:

function(response){
 var result = response.data;
 var statusCode = result.status;
 var responseData = result.myApiResponse;
} 

更多信息请查看:https://github.com/mgonto/restangular#setfullresponse,希望我的post对您有所帮助。