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

时间:2018-05-14 07:30:19

标签: node.js angular typescript express httpclient

所以我在角度5的顶部制作网络应用程序。 问题是当我尝试从服务器调用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');
});

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

1 个答案:

答案 0 :(得分:0)

经过大量调试,我找出了引起我的问​​题。在每个请求中,我都发送了移动设备的名称,对于我来说,它是 Shashank的iPhone

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