所以我在 Angular 5 之上制作 Web 应用程序。 问题是当我尝试从服务器调用 api 端点时。
当我收到错误响应(400+)时,似乎在 Safari 上它总是抛出并破坏应用程序。
ERROR - TypeError: Type error
ERROR CONTEXT – DebugContext_ {view: Object, nodeIndex: 0, nodeDef: Object, …}
但在 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');
});
有人知道如何解决这个问题吗?
最佳答案
经过大量调试后,我找出了导致我出现问题的问题。在每个请求中,我都会发送移动设备的名称,就我而言,它是 Shashank 的 iPhone。
调用setRequestHeader
header 中带有 单引号 失败,因此所有 HTTP 请求都中断了。
关于node.js - 错误 - 类型错误 : Type error only on Safari after made GET request to the api server inside angular 5 app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50325080/