Skip to content

Error objects should be more consistent #77

@ambarth

Description

@ambarth

Superlogin-client api returns very different error objects depending on what goes wrong. There are at least three different cases:

  1. No network connection: If superlogin-client can not even connect to the superlogin server there will be an error object err with a message property with value 'Network Error' and err.response and err.status will be undefined (err.response at least exists as key). I think this is due to axios.

  2. 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 error property that has a string value explaining what is the problem, for example here:

    return Promise.reject({ error: 'Username or Password missing...' });

  3. 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 error and a message property both of which have a string value sent by superlogin. However, the error code sent by the server gets lost here:

    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions