错误 - TypeError:在对angular 5 app内的api服务器发出GET请求后,仅在Safari上键入错误

问题描述 投票:2回答:1

所以我在角度5的顶部制作Web应用程序。问题是当我尝试从服务器调用api端点时。

当我收到错误响应(400+)时,似乎在Safari上它总是抛出并打破应用程序。

ERROR - TypeError: Type error
ERROR CONTEXT – DebugContext_ {view: Object, nodeIndex: 0, nodeDef: Object, …}

enter image description here

但在Chrome上,它可以像这样正确处理错误。

GET https://api.xxxx.com/projectname/v1.0/validation/access-token 400 (Bad Request)

这是我的源代码

const baseUrl = environment.apiUrl;
const fullUrl = baseUrl + '/productname/v1.0/validation/access-token';

const headers = new HttpHeaders({
     'X-Access-Token': access_token
});

this.http.get(fullUrl, {
    headers: headers
}).subscribe((res: any) => {
   console.log(res, 'http res');
},
(error: any) => {
    console.log(error, 'http err');
});

任何人都知道如何解决这个问题?

node.js angular typescript express httpclient
1个回答
0
投票

经过大量调试后,我发现了导致我的问题。在每个请求中,我都发送了移动设备的名称,而我的情况则是Shashank的iPhone。

在标题中使用单引号调用setRequestHeader失败,因此所有HTTP请求都中断。

© www.soinside.com 2019 - 2024. All rights reserved.