Open arvraham opened 7 years ago
Agreed - this could be more solid. Note that we do expect a valid JSON response from the server conforming to a certain format, otherwise, how can we parse what the token value is? But yes, it shouldn't crash!
Feel free to send a PR with what you have in mind and we'll take it from there. Thanks!
When making requests to a backend, it goes like this:
If server responses with something other than valid json
JSON.parse
will crash.I thought about it a while and came to believe that authenticator mustn't rely solely on response bodies. Status codes should be evaluated before going into detail. For the authenticator it is important to know whether a token is valid or not. Logging reasons is nice and often useful but it mustn't have side effects.
By the way: Fetch responses support parsing json directly: