2

I'm using Angular 5.2.2 and CLI 1.6.5, I have a component with method

getRecentMattersForUser(userId: string) {
    this.matterService.getRecentMattersForUser(userId)
        .subscribe(matters => {
        this.matters = matters;
    },
    error => this.errorMessage = JSON.stringify(error));
}

Service

getRecentMattersForUser(userId: string): Observable<Matter[]> {
    const matterService = environment.serviceBaseUrl + '/Matters?requestFor=' + userId;
    const headers = new HttpHeaders({ 'Content-Type': 'application/json' });

    return this.http.get<Matter[]>(matterService, {
        withCredentials: true,
        headers: headers
    });
}

On my desktop this lists matters nicely with an *ngFor but in Safari on iOS errorMessage prints:

{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":null,"ok":false,"name":"HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown Error","error":{"isTrusted":true}}

What's the difference?

I used to use the old Http (instead of HttpClient) like so

private options = new RequestOptions({ 'withCredentials': true });

getRecentMattersForUser(userId: string): Observable<any> {
    const matterService = environment.serviceBaseUrl + '/Matters?requestFor=' + userId;

    return this.http.get(matterService, this.options)
        .map(this.extractData);
}

Which still works.

Any ideas?

Anna
  • 2,988
  • 3
  • 15
  • 29
John Doe
  • 188
  • 1
  • 14
  • you might need to upgrade es6-shim : https://www.npmjs.com/package/es6-shim. Also, check this: https://stackoverflow.com/questions/44901352/angular-2-login-not-working-in-safari-and-firefox – Akash Agrawal Jan 30 '18 at 06:10
  • Removed setting the header and it started working in Safari as well, will have to read up on the doco again and see what I've missed in the later updates. – John Doe Jan 31 '18 at 01:28
  • Did you find a fix ? Thank you – Joe Allen Jun 04 '18 at 15:14
  • Yeah I just removed setting the header with content-type so in the example above: return this.http.get(matterService, { withCredentials: true }); Still need to set the content-type for http post if I remember correctly, don't have access to that source anymore. – John Doe Jun 05 '18 at 23:03
  • Solution here: https://stackoverflow.com/questions/48557390/angular-4-http-failure-response-for-unknown-url-0-unknown-error – Manish Jain Feb 25 '19 at 22:46

0 Answers0