nordnet / nordnet-next-api

Nordnet nExt API Javascript client
27 stars 11 forks source link

Fix no response failure #12

Closed elenate closed 7 years ago

elenate commented 7 years ago

Sometimes it can happen that API will respond with empty body, and you will not get response and status code, which is bad, but you get internal Fetch error, but it also dousnt help and its only source of confusion. So by adding this, catch we can gracefully handle invalid API response

dimchez commented 7 years ago

I would say that if body is empty and response status code is 2xx then promise should not be rejected. Is the response code 204 when body is empty or is it 200?

iamstarkov commented 7 years ago

Is the response code 204 when body is empty or is it 200?

no, response code is 403

dimchez commented 7 years ago

Ok, then it makes sense.

iamstarkov commented 7 years ago

the only reason why promise is rejected its because for whatever reason fetch cant handle response and explodes, and rejecting the promise makes sense because its not normal flow