# Code and Formats
source: https://developer.mastercard.com/community-pass-payment-apis/documentation/code-and-formats/index.md

## Errors Handling {#errors-handling}

We use standard HTTP response codes for success and failure notifications. In general, 200 HTTP codes correspond to success, 40X codes are for developers or user-related failures.

## Gateway Error Codes {#gateway-error-codes}

Apart from the error codes returned by the MCPP APIs, error codes can be returned by the Mastercard gateway, which verifies your request's signature and routes to the correct location.

For further information about 4xx/5xx response codes and possible resolutions, please refer to [Gateway Error Codes](https://developer.mastercard.com/platform/documentation/gateway-error-codes/)

## Error Structure {#error-structure}

To ensure a consistent experience across all Mastercard APIs, MCPP APIs follow the below structure for error scenarios.

Single Error :

```JSON
{
  "Errors": {
    "Error": [
      {
        "Source": "<source>",
        "ReasonCode": "<unique code>",
        "Description": "<short description of the error>",
        "Recoverable": true/false,
        "Details": "<Optional detailed description of the issue>"
      }
    ]
  }
}
```

Multiple Errors :

```JSON
{
  "Errors": {
    "Error": [
      {
        "Source": "<source>",
        "ReasonCode": "<unique code>",
        "Description": "<short description of the error>",
        "Recoverable": true/false,
        "Details": "<Optional detailed description of the issue>"
      },{
        "Source": "<source>",
        "ReasonCode": "<unique code>",
        "Description": "<short description of the error>",
        "Recoverable": true/false,
        "Details": "<Optional detailed description of the issue>"
      }
    ]
  }
}
```

|      Field      |                                                                                                                                                                       Description                                                                                                                                                                       |
|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Source**      | The application that generated this error. Every error message that is generated and returned by the gateway will have this field equal to 'Gateway'. When the value of the source field is something other than 'Gateway', it means the error was generated elsewhere.                                                                                 |
| **ReasonCode**  | A unique constant identifying the error case encountered during MCPP APIs. For example, INVALID_SIGNATURE is used when the request signature does not match the expected one.                                                                                                                                                                           |
| **Description** | Short description of the ReasonCode field.                                                                                                                                                                                                                                                                                                              |
| **Recoverable** | Indicates whether this error will always be returned for this request, or retrying could change the outcome. For example, if the request contains an invalid signature, retrying will never result in a success. However, if the error is related to some unexpected timeout with the service, retrying the call could result in a successful response. |
| **Details**     | Where appropriate, indicates detailed information about data received and calculated during request processing, to help the user with diagnosing errors.                                                                                                                                                                                                |

## MCPP APIs Specific Errors {#mcpp-apis-specific-errors}

Note: Following error codes are specific to MCPP APIs, so for all errors in the below table, Source will be returned as `PAYMENTS_SERVICE`. For any error with source other than `PAYMENTS_SERVICE`, please refer to the [Gateway Error Codes](https://developer.mastercard.com/platform/documentation/gateway-error-codes/) for possible resolutions.

For a complete list of MCPP APIs specific error codes, please refer to the below table:

|       Reason Code        | Http Status Code |                               Description                                |                                                                                        Tip to Resolve                                                                                         |
|--------------------------|------------------|--------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **INVALID_KEY**          | 403              | Signing certificate must be valid.                                       | The signing certificate is not valid. The user will have to regenerate the signing certificate by logging into the Mastercard developers , or they might be using invalid signing certificate |
| **INVALID_AUTH_HEADER**  | 400              | Bad Request - No Authorization header set.                               | Please check if you are passing the key to call the API                                                                                                                                       |
| **DECLINED**             | 401              | Unauthorized - Access Not Granted.                                       | Please check if your key has not been revoked                                                                                                                                                 |
| **BAD_REQUEST**          | 400              | We cannot handle your request.                                           | If the request payload has some data that is different from what the API expects, you will see this error                                                                                     |
| **NOT_FOUND**            | 404              | The requested resource was not found on this server.                     | If the requested end point does not exist , you will see this error                                                                                                                           |
| **ACCOUNT_NOT_FOUND**    | 404              | We cannot find the account that you are using to access this service.    | Your account requested for validation does not exist                                                                                                                                          |
| **CLIENT_ID_NOT_FOUND**  | 404              | We cannot find the client id that you are using to access this service.  | Your payload contains client id that is not valid                                                                                                                                             |
| **API_ACTION_NOT_FOUND** | 404              | We cannot find the API action that you are using to access this service. | Your payload contains an API action that is not valid                                                                                                                                         |

Sample of MCPP APIs error object :

```JSON
{
   "Errors": {
       "Error": [
           {
               "Source": "PAYMENTS_SERVICE",
               "ReasonCode": "INVALID_KEY",
               "Description": "The signing certificate is not valid.",
               "Recoverable": false,
               "Details": null
           }
       ]
   }
}
```

