0

so I am using forkJoin to create multiple calls to the http service as in

  let observables = [
     this.http.get('/app/books.json').map((res:Response) => res.json()),
     this.http.get('/app/movies.json').map((res:Response) => res.json())
];

Observable.forkJoin(observables).subscribe(
   data => {
        this.books = data[0]
        this.movies = data[1]
   },
   err => console.error(err)
);

which works great, the only issue is that if a particular call fails, I get no info on why (I just get back a OK and status 200 on the err:Response object)

I do see the error in he console but not in the reponse back.

any way to retrieve it?

tx

Sean

enter image description here

born2net
  • 24,129
  • 22
  • 65
  • 104
  • could you make sure, server is reachable? and the error which you are getting is happening from somewhere else.. because URL in console is different than what you have in `Observable.forkJoin` method – Pankaj Parkar Apr 07 '16 at 18:36
  • well that's the thing, I am putting it into a invalid URL on purpose to test it out, so I can see how to catch error in runtime IF and WHEN a server is down... the issue is that with Observables I can't seem to catch the error reason ( I can catch the error but not the details, as in Connection timed out for example...) – born2net Apr 07 '16 at 18:46

1 Answers1

2

I investigated a bit this issue. It's not really related to the user of Observable.forkJoin. In fact, you can't have the exact message. I mean the net::ERR_CONNECTION_TIME_OUT. XHR doesn't provide it.

That said, you can see that the status of XHR is 0. This could be an hint that there was a problem the request when sending the request (it's not actually sent).

error => {
  (...)
  var err = error.json();
  var status = err.currentTarget.status;
  (...)
}

See this question:

Community
  • 1
  • 1
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • tx, I was looking also into mapping the status, do you know if each error has it's own code (RFC maybe?), if so that would suffice as I could map it internally... tx as always for the great support!!! – born2net Apr 07 '16 at 21:58
  • found this but not really "codes" https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest – born2net Apr 07 '16 at 22:07