Errors

In this guide, we will talk about what happens when something goes wrong while you work with the Leabank API. 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 type and error message 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 API. Use these to understand if a request was successful.

  • Name
    2xx
    Description

    A 2xx status code indicates a successful response.

  • Name
    4xx
    Description

    A 4xx status code indicates a client error — something was wrong with the request (e.g. missing fields, invalid values, authentication issues).

  • Name
    5xx
    Description

    A 5xx status code indicates a server error — something went wrong on our end. If this persists, please contact support.


Error response format

Whenever a request is unsuccessful, the API will return an error response with a message and an errors array. Each entry in the errors array contains:

  • Name
    path
    Type
    string
    Description

    The JSON path to the field that caused the error (e.g. .body.applicant.maritalStatus).

  • Name
    message
    Type
    string
    Description

    A human-readable description of the error.

  • Name
    errorCode
    Type
    string
    Description

    A machine-readable error code identifying the type of validation failure.

Error response

{
  "message": "request.body.applicant.maritalStatus should be equal to one of the allowed values: Single, Married, Divorced, Widower, Separated, CoHabiting",
  "errors": [
    {
      "path": ".body.applicant.maritalStatus",
      "message": "should be equal to one of the allowed values: Single, Married, Divorced, Widower, Separated, CoHabiting",
      "errorCode": "enum.openapi.validation"
    }
  ]
}

Common error codes

The errorCode field helps you programmatically identify the type of validation failure. Here are the most common error codes you may encounter:

  • Name
    enum.openapi.validation
    Description

    The provided value is not one of the allowed values. Check the allowed values listed in the error message.

  • Name
    required.openapi.validation
    Description

    A required field is missing from the request body.

  • Name
    type.openapi.validation
    Description

    The provided value has the wrong type (e.g. a string was provided where a number is expected).

  • Name
    format.openapi.validation
    Description

    The provided value does not match the expected format (e.g. an invalid email or date format).

  • Name
    pattern.openapi.validation
    Description

    The provided value does not match the expected pattern (e.g. a national ID format).

Missing required field

{
  "message": "request.body.applicant.nationalId is required",
  "errors": [
    {
      "path": ".body.applicant.nationalId",
      "message": "is required",
      "errorCode": "required.openapi.validation"
    }
  ]
}

Wrong type

{
  "message": "request.body.loan.amount should be number",
  "errors": [
    {
      "path": ".body.loan.amount",
      "message": "should be number",
      "errorCode": "type.openapi.validation"
    }
  ]
}

Multiple validation errors

A single request can trigger multiple validation errors. In this case, the errors array will contain one entry for each validation failure. The top-level message will describe the first error.

Multiple errors

{
  "message": "request.body.applicant.nationalId is required",
  "errors": [
    {
      "path": ".body.applicant.nationalId",
      "message": "is required",
      "errorCode": "required.openapi.validation"
    },
    {
      "path": ".body.applicant.email",
      "message": "should match format \"email\"",
      "errorCode": "format.openapi.validation"
    },
    {
      "path": ".body.loan.amount",
      "message": "should be number",
      "errorCode": "type.openapi.validation"
    }
  ]
}

Authentication errors

If your request is missing a valid token or the token has expired, you will receive a 401 Unauthorized response. If your token does not have the required scopes, you will receive a 403 Forbidden response.

See the Authentication guide for details on how to obtain and refresh tokens.

401 Unauthorized

{
  "message": "Unauthorized"
}

403 Forbidden

{
  "message": "Forbidden"
}

Was this page helpful?