Errors

In this guide, we will talk about what happens when something goes wrong while you work with the API. Mistakes happen, and mostly they will be yours, not ours. Let's look at some status codes and error types you might encounter.

You can tell if your request was successful by checking the status code when receiving an API response. If a response comes back unsuccessful, you can use the error message and code to figure out what has gone wrong and do some rudimentary debugging (before contacting support).


Status codes

Here is a list of the different categories of status codes returned by the Fystack API. Use these to understand if a request was successful.

  • Name
    2xx
    Type
    Description

    A 2xx status code indicates a successful response.

  • Name
    4xx
    Type
    Description

    A 4xx status code indicates a client error — this means it's a you problem.

  • Name
    5xx
    Type
    Description

    A 5xx status code indicates a server error — you won't be seeing these.


Error response format

Whenever a request is unsuccessful, the Fystack API will return an error response with a structured format. All error responses include a success field set to false, a descriptive message, and an error code. For validation errors, you'll also see an errors array containing details about which fields failed validation.

Here are the common components of an error response:

  • Name
    success
    Type
    Description

    Always false for error responses.

  • Name
    message
    Type
    Description

    A human-readable description of what went wrong.

  • Name
    code
    Type
    Description

    An internal error code that can help with debugging.

  • Name
    errors
    Type
    Description

    For validation errors, contains details about which fields failed validation and why.

Standard error response

{
  "success": false,
  "message": "Resource not found",
  "code": 404
}

Validation error response

{
  "success": false,
  "message": "validation error",
  "code": 400,
  "errors": [
    {
      "field": "email",
      "reason": "required"
    },
    {
      "field": "password",
      "reason": "min=8"
    }
  ]
}

Error codes

The Fystack API uses specific error codes to help identify the exact issue that occurred. These codes provide more granular information than HTTP status codes alone.

Code Name Description
2407ValidationErrCodeReturned when request data fails validation requirements.
2408GenerationErrCodeIndicates an error occurred during content or resource generation.
2409DatabaseErrCodeReturned when a database operation fails.
2410ConflictErrCodeIndicates a conflict with the current state of the resource.
2411InfraErrCodeReturned when an infrastructure-related error occurs.
2412RedisErrCodeIndicates a problem with Redis cache operations.
2413ForbiddenResourceErrCodeReturned when the user does not have access to the requested resource.
2414ForbiddenActionErrCodeIndicates the user is not allowed to perform the requested action.
2415UnauthorizedErrCodeReturned when authentication is required but missing or invalid.
2416ExecutionErrCodeIndicates an error during the execution of a command or process.
2417NotFoundErrCodeReturned when the requested resource doesn't exist.
2418EncodingErrCodeIndicates an error occurred while encoding data.
2419DecodingErrCodeReturned when there's an error decoding data.
2420InternalResourceNotFoundIndicates a required internal resource could not be found.
2421BadRequestErrCodeReturned when the request is malformed or contains invalid parameters.
2422InternalErrCodeIndicates an unexpected internal server error occurred.