alt

Important information

The API reference is now available here.
The deprecated API reference is available here.

Unzer

Error handling

Error and debug information provided by Unzer API and SDK.

Overview

Unzer API errors are returned in the JSON response and consist of a code, merchantMessage and customerMessage. We recommend showing the customer message in the frontend and logging all fields of unexpected errors for further investigation.
You should also store the fields id and traceId that are useful when you need to find the root cause for an error. The id can also be used to fetch a specific error object later for analysis (see below).

icon info
Error responses do not always have an HTTP error status code.
That means, the response would have a 2XX HTTP status code that still has a list of errors in its payload.
{
  "id": "p-err-d0d2096c9bb04a2e8cecf776601",
  "isSuccess": false,
  "isPending": false,
  "isError": true,
  "url": "https://api.unzer.com/v1/customers",
  "timestamp": "2021-07-30 11:43:39",
  "traceId": "b7842b4951bc3752406e6e3f3c51a217",
  "errors": [
    {
      "code": "API.410.200.001",
      "merchantMessage": "lastName is missing",
      "customerMessage": "lastName is missing. Please contact us for more information."
    },
    {
      "code": "API.410.200.004",
      "merchantMessage": "firstName is missing.",
      "customerMessage": "firstName is missing. Please contact us for more information."
    }
  ]
}

HTTP response codes for errors

CodeHTTP ResponsePossible causes
400Bad RequestBad request to the API, for example, required parameter is missing or has an invalid syntax.
401UnauthorizedRequest without a key or with an invalid key.
403Access-Denied/ForbiddenRequest to a private resource with a public key.
404Not FoundThe requested resource does not exist.
405Method Not AllowedThe chosen payment type is not configured for the merchant or the HTTP method can not be used for the requested resource.
415Unsupported media typeThe request media type is not supported by the system.
500Internal Server ErrorAn error occurred in an internal Unzer system.
504Gateway TimeoutThe server did not receive a fast enough response from another server upstream when it attempted to load one of the web pages.

Error resource components

Error responses are always returned with information about the origin of the error in the form of a JSON object. Within the error object, there is a list of errors to provide you with all possible problems in a chunk.

{
    "code": "API.410.200.004",
    "merchantMessage": "firstName is missing.",
    "customerMessage": "firstName is missing. Please contact us for more information."
}
KeyDescription
codeUniquely identifies the error, it could look like this: API.410.200.004
merchantMessageSpecifies the error details and further information for you as a merchant. The message is not intended to be displayed to the customer. This message is only visible if you make the call with a private key. If you are using a public key, this field is missing.
customerMessageSpecifies the message to be displayed to your customer. It is available in several languages, based on the Accept Language header.

Retrieving errors by ID

Fetching an error is not possible via Java SDK. Please refer to Fetch error object of the Direct API integration documentation.

Handling server-side errors

When error occurs, this will cause an PaymentException that needs to be handled.

The exception is thrown if there is an error connecting to the API or to the payment core.

If there is an error executing a request the Java SDK will throw a HttpCommunicationException.

To identify the error, you should catch this exception and write it to your error log and show the clientMessage to your customer.

try {
    Unzer unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY);
    Charge charge = unzer.charge(BigDecimal.valueOf(119.0), Currency.getInstance("EUR"), paymentTypeId, "https://your.return.url");
} catch (UnzerApiException | HttpCommunicationException e) {
    // write e.getMerchantMessage(), e.getErrorId() and e.getCode() to your log
    // show e.getClientMessage() on the client side if applicable
}

Runtime Exceptions

In some cases the SDK throws a unspecified Exception. This is the case when there is an error using the SDK for example, the key is in wrong format, is not the private key, or when a necessary resource does not exist.

We recommend you to catch those exceptions and handle them by writing them to your error-log and showing a generic error-message to the customer.

try {
    // your call to the api
} catch (SpecifiedException ex) {
    //  write ex.getMessage() to your error log
    //  redirect your customer to a failure page and show a generic message
}

Debug log

Custom Debug-Logging is not supported in Java SDK.

See also

Error codes
Notifications