Skip to content

What is the best approach to manage custom user errors? #560

@jferrettiboke

Description

@jferrettiboke

I am very interested to know how to talk with the client with custom errors.

For example, if you create a new user and the user email already exists on the database, the API has to be able to reply to the client with a custom error. What is the best approach to achieve this?
Maybe, some of you start thinking that this has to be controlled by the client UI, but sometimes, an API is used by different clients or third-party apps. So, it is very important to detect all the errors on the API as well.

At this moment, I manage the custom errors by this way, but I am not pretty sure if it is the best approach.

mutation {
  signUp(email: "[email protected]", password: "123") {
    token
    errors {
      key
      value
    }
  }
}
"data": {
  "signUp": {
    "token": null,
    "errors": [{ "key": "user.exists", "value": "There is already a user with this email." }]
  }
}

If you want to share your approach to achieve this, I will be very happy to read about it.

I think we should consider this to add to the documentation on http://graphql.org/graphql-js/. In my opinion, it is very important to manage all the errors properly to build good GraphQL APIs.

Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions