Routefusion Error Messages
Routefusion error messages are designed to be human-readable and easily parsable. They fall into three categories:
- Authentication Errors
- GraphQL Errors
- Validation Errors
- Im a Teapot
Authentication Errors
All authentication errors will produce HTTP 401 status codes. These errors can be caused by:
- A bad or missing bearer token.
- Attempting to run a query that your user/token does not have access to.
Authentication errors are intentionally vague and will return the following message:
{
"message": "unauthorized"
}
GraphQL Errors
GraphQL errors can occur due to malformed queries or malformed variables. These errors will produce an HTTP 400 status code and will be included in the errors
array.
Example:
{
"errors": [
{
"message": "Cannot query field \"createUer\" on type \"Mutation\". Did you mean \"createUser\" or \"updateUser\"?",
"path": [
"userWithID"
],
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED"
}
}
]
}
Validation Errors
Validation errors are a type of GraphQL error that occur when required variables are not provided or when provided data is malformed. These errors will produce an HTTP 200 status code and will be included in the errors
array.
Causes of Validation Errors:
-
Missing Required Variables: Occurs when a required variable is not provided.
- Example:
{ "errors": [ { "message": "Variable account_number required", "path": [ "userWithID" ], "extensions": { "code": "BAD_USER_INPUT" } } ] }
-
Malformed Data: Occurs when provided data does not match the expected format. These errors include detailed messages, including the regex used for validation.
Example Regex for Parsing Errors:
const fieldValidationRegex = /Variable:?\s\"?\$?(?<variable>\w+)\"?.?\s(Message:\s(?<message>([^.]+)))?(.\s)?(Regex:\s(?<regex>([^.]+)))?(.\s)?(Example:\s(?<example>([^.]+)))?/;
const requiredRegex = /Variable\s\"?\$?(?<variable>\w+)\"\srequired/;
Example:
{
"errors": [
{
"message": "Variable account_number required",
"path": [
"userWithID"
],
"extensions": {
"code": "BAD_USER_INPUT"
}
}
]
}
Im a Teapot Error
{
"message": "I'm a teapot. I can't brew coffee, but I can make a mean cup of tea!"
}
This error occurs when the server refuses to brew coffee because it is, quite literally, a teapot.