-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Superlogin-client api returns very different error objects depending on what goes wrong. There are at least three different cases:
-
No network connection: If superlogin-client can not even connect to the superlogin server there will be an error object
errwith amessageproperty with value 'Network Error' anderr.responseanderr.statuswill be undefined (err.responseat least exists as key). I think this is due to axios. -
superlogin-client detects some constraint violation on the client side (for example the username field or password is missing) and rejects the api call with an error object with a single
errorproperty that has a string value explaining what is the problem, for example here:superlogin-client/src/index.js
Line 336 in 56fd477
return Promise.reject({ error: 'Username or Password missing...' }); -
superlogin-client successfully connects to the superlogin server, but it returns an error code (for example the credentials do not match etc.). In this case the error object is simply the response body sent by the server. Unless there is some other server side error it will have an
errorand amessageproperty both of which have a string value sent by superlogin. However, the error code sent by the server gets lost here:
superlogin-client/src/index.js
Line 43 in 56fd477
function parseError(err) {
In short handling superlogin-client error handling would look something like this:
if (!err.response && err.message === 'Network Error') {
// network connection failed
} else if (err.error && typeof err.status === 'undefined') {
// constraint violation, err.error is a string explaining the problem
} else {
// err is the response body sent by the server, but it might look different depending on what happened,
// it could be the superlogin response or anything else you send on the server
// since we do not even have the status code its hard to tell what the problem is
}A first step to improve this would be to let attach the status code to the error object in parseError.
We could use status 0 for the case where no connection could be established.