Errors and HTTP status codes

HTTP status codes

HTTP status codes are used to indicate the status of an HTTP request made to a Mono API. There are several different types of status codes, each of which indicates a different outcome for the request. Here are some of the HTTP status codes Mono API uses:

StatusNotesMethods
200 (OK)Request completed successfullyGET
201 (Created)Indicates that a new resource was created as a result of the requestPOST
204 (NoContent)Indicates that the request was successful, but there is no additional information to send back to the client.DELETE
400 (BadRequest)Request has malformed, missing or non-compliant JSON body, URL parameters or header fieldsALL
401 (Unauthorized)Authorization header missing or invalid tokenALL
403 (Forbidden)Client doesn't have access to a resource or token is invalidALL
404 (NotFound)Client attempts to retrieve a resource that is not defined or not existALL
422 (UnprocessableEntity)Request structure is valid, but the content coudn't be processedALL
500 (InternalServerError)Something went wrong on the ServerALL

Errors

Every request that returns an error, the API will return an standard error structure, it includes several attributes that provide information about the error:

  • code: This attribute contains a string that represents the HTTP status code and phrase for the error. For example, "404 Not Found" or "500 Internal Server Error".

  • errors: This attribute is an array of objects that contain information about specific errors that occurred. Each object includes the following attributes:

    • error_code: This attribute contains a string that represents a unique code for the error. This code can be used to identify the specific type of error that occurred.

    • message: This attribute contains a string that provides a brief description of the error.

    • path: This attribute contains a string that represents the location of the error within the request payload.

    • url: This attribute contains a string that represents a URL to a documentation page that provides more information about the error.

  • id: This attribute contains a string that represents a unique identifier for the error. This can be used to track the error for debugging or logging purposes.

  • message: This attribute contains a string that provides a brief description of the error. This message is intended for humans to read and understand, and may be displayed to the user if the error is encountered.

Here's an example that how it will be returned:

{
  "code": "400 Bad Request",
  "errors": [
    {
      "error_code": "item_not_found",
      "message": "Item doesn't exist",
      "path": "#/item/id",
      "url": "https://{{api_domain}}/docs#errors"
    }
  ],
  "id": "log_7MkWaFqvfosB8fzHhb1Eql",
  "message": "Malformed request"
}