HTTP call done twice
gorghoa opened this issue · comments
The APIService::getCollectionByUrl()
trigger the http call twice (to be clear, I’m not talking about the OPTIONS http method here). This is due to the query.subscribe
used to handle an error.
My opinion is we should not interfere with the Rxjs observable error workflow and let the error live is nasty little life until someone who knows how to handle it catch it up.
Still in my opinion and arguably, the error should almost never be catched by the APIService. The error should bubble up to the final subscriber.
Anyhow, I bet that the error workflow is broken here since the exception is thrown asynchronuously and therefore is hardly catchable.
In case that my point was not clear: My fix proposition is to remove this subscription purely and simply ;)
Let the component handle the error on their own is pain in the ass IMO, but I think a share
operator should solve the problem (to share the last result without rebuild the whole process on each subscribe)
Anyhow, who is responsible for catching your exception today? And (genuinely) how is the exception catchable? given the asynchronous stuff.
IMO, it should be the service
This exception is wrong anyway :
- Using angular2-jwt : when there are no jwt token, I get this exception instead of the one throw by angular2-jwt.
OK.
So for you two, what is the best ? Be able to have raise both exception (maybe only take care of 404 in service) or catching the same error on each component that can't reach the API ?
I would like to see both exception, catch any of them before the call and then catch this one if there is a problem without making two calls ;)