# API Error Handling
source: https://developer.mastercard.com/mastercard-gateway/documentation/testing/api-error-handling/index.md

When you send a request to the Mastercard Gateway, you receive an HTTP status code as part of the response. This code lets you know whether the gateway has successfully received and processed your request.

The following sections describe the HTTP status codes used by the gateway.

## Success: 201 code {#success-201-code}

The gateway uses the 201 status code for successful requests, where it has received the request, parsed it successfully, and mapped it to a valid API operation.

Warning: The 201 status code does not necessarily mean that the payment transaction within the request has been successful, only that the gateway has been able to process the request. Even if the acquirer declines the payment and the transaction fails, the gateway returns the 201 status code, as the request itself has been successfully executed. For more information about determining the transaction status and dealing with specific transaction errors, see \[Transaction Errors\].

<br />

## Client-side error: 4XX codes {#client-side-error-4xx-codes}

The status codes in the 4XX range refer to a problem on the client side, within the request you sent.

The exact code defines the type of the problem. The most common codes are:

* 400 code is used when the request is malformed, and the gateway cannot parse it.  

  Check the request structure for valid format and all mandatory fields present, then resend the request.

* 401 code is used when the authentication for the request fails.  

  Check the authentication credentials that you are using in the request and resend it.

Warning: When the request fails due to a client-side error, the error.cause field in the response body is set to INVALID_REQUEST. The same value is used to both when the request is malformed and if there is a problem with authentication. Always check the HTTP status code to understand the exact reason for the problem.

## Server-side error: 5XX codes {#server-side-error-5xx-codes}

The status codes in the 5XX range refer to a problem on the gateway side. The most common code is 500, which is returned when the gateway encounters an error when processing your request. If you receive a 5XX code from the gateway, then keep resending your request at reasonable intervals for every first few seconds and then every minute. If the problem persists for an hour or more, contact your support team at your payment service provider or Mastercard Gateway.
