ErrorResponse Class
Use to respond with an error after receiving errors from the PaymentGatewayAdapter methods of the CommercePayments namespace, such as request-forbidden responses, custom validation errors, or expired API tokens.
This example snippet of a mock tax adapter shows a hypothetical scenario to demo an error response. The adapter receives request information from TaxEngineContext and stores it in an instance of CalculateTaxRequest. If the request’s documentCode property is null or indicates an error, the adapter returns an error response with information about the error.
-
Learn more about the available constructors with the
ErrorResponseclass.
Learn more about the available constructors with the ErrorResponse class.
The ErrorResponse class includes these constructors.
-
ErrorResponse(resultCode, errorCode, errorMessage)
Constructor to initialize an
ErrorResponseobject from the result code, error code, and error message sent from the tax engine.
Constructor to initialize an ErrorResponse object from the result code, error code, and error message sent from the tax engine.
global ErrorResponse(commercetax.ResultCode resultCode, String errorCode, String errorMessage)
-
resultCode:
Type: ResultCode
Code for the type of result sent by the tax engine.
-
errorCode:
Type: String
Code for the type of error sent by the tax engine. Codes must match the HTTP status codes to be returned to the user. Here are a few examples:
- If the status code is for a bad request, set
errorCodeto400. - If the status code is for a forbidden request, set
errorCodeto403. - If
errorCodeisn’t a valid HTTP status code, a 500 internal server error is returned.
- If the status code is for a bad request, set
-
errorMessage:
Type: String
The error message sent by the tax engine.