Menu

Handling errors

Errors

Copied!
{
    "httpStatusCode":400,
    "customCode":"BAD_REQUEST",
    "message":"Some request parameters are invalid",
    "description":"Bad request, please check your request",
    "errorHelpUrl":null,
    "originalRequest":{... original request json object ...}
}
try {
    // Worldpay Method, for example:
    // $worldpay->refundOrder('your-order-code');
} catch (WorldpayException $e) {
    echo 'Error code: ' . $e->getCustomCode() . ' 
    HTTP status code:' . $e->getHttpStatusCode() . ' 
    Error description: ' . $e->getDescription()  . ' 
    Error message: ' . $e->getMessage();
} catch (Exception $e) { 
    echo 'Error message: '. $e->getMessage();
}
try {
    // Worldpay Method, for example:
    // OrderResponse orderResponse = restClient.getOrderService().refund('your-order-code');
} catch (WorldpayException e) {
    System.out.println("Error code: " + e.getApiError().getCustomCode());
    System.out.println("Error description: " + e.getApiError().getDescription());
    System.out.println("Error message: " + e.getApiError().getMessage());
}
begin
    # Worldpay Method, for example:
    # response = worldpay.refundOrder('your-order-code')
rescue Exception => e
    print e.to_s
end
try {
    // Worldpay Method, for example:
    // OrderResponse orderResponse = restClient.GetOrderService().Create(orderRequest);
} catch (WorldpayException e) {
    Console.WriteLine("Error code:" + e.apiError.customCode);
    Console.WriteLine("Error description: " + e.apiError.description);
    Console.WriteLine("Error message: " + e.apiError.message);
}

If an error occurs on your call, a JSON object with the error details is returned. The code on the right shows you how to handle errors in different languages.