Error Handling in Synqpay
Synqpay uses the JSON-RPC protocol to handle errors during communication between the client and the payment device. This document explains how errors are structured and handled within this protocol, including the error hierarchy and various types of errors that may be encountered.
Error Hierarchy
Transport Layer Errors
These errors occur at the transport layer and are not related to the processing of the JSON-RPC request itself. They typically indicate issues with the underlying connection or authorization. This is the highest level of errors that may occur, emphasizing their position at the top of the error hierarchy.
Each transport layer error contains additional data regarding the specific issue, such as HTTP status codes or connection error details, to help identify and resolve the problem.
Example: HTTP 401 Unauthorized
This occurs if the client is not authorized to access the requested resource.
JSON-RPC Errors (Method-Specific Errors)
All methods process the requests and return a response once the processing is complete. The response will indicate whether the operation was successful or not. Hence, the response will either include an Error
object or the method's Result
object according to JSON-RPC and method specs, depending on the outcome of the request.
The Error
objects are thrown when the request cannot be processed due to issues within the method itself, such as invalid parameters or an unsupported operation. Each method specifies the types of errors it may throw, and these errors prevent the request from being processed. The errors are listed in the Errors page
Example
Response Handling for Methods with Processing Results
Some methods include result
field within the Result
object. This field indicates whether the processing was successful or not:
- Successful Processing: The
result
field confirms that the operation was completed successfully. - Error During Processing: If an issue occurs during processing (e.g., user cancellation or timeout), the
result
field will indicate the failure and provide more details about the processing.
See Result Enumerator for possible outcome for this field.
- Key Point:
The presence of a
result
field in the response is typical for methods involving longer operations, such as transaction processing, or cancelable operations. This field provides the final outcome of the operation once it is complete.
Example: User canceled the transaction processing
Transaction-Specific Errors
Transaction requests have a special error handling structure. The result
field in the response indicates whether the transaction was successful or not, but there's an additional level of error handling when HOST_ERROR
is encountered.
-
Approved Transaction:
If the transaction is successfully approved, the result will beOK
, and the transaction has been processed. -
Transaction Failure with
HOST_ERROR
:
If the transaction is not approved, theresult
may beHOST_ERROR
. This indicates that the transaction could not be processed because of a host-level decision, such as Online decline where The transaction was declined by the host or Processing failure where The host determined that the transaction request was invalid for some reason. In the case of aHOST_ERROR
, thetransaction
object is nested within the result object and contains additional details about the transaction, including the host error:hostErrorCode
: A code representing the specific error returned by the host.hostErrorMessage
: A human-readable message describing the error returned by the host.
-
Best Practice:
While theHOST_ERROR
in the result field indicates a failure, it is recommended to also check thetransactionStatus
field (e.g.,CAPTURED
,DECLINED
, etc.) for more detailed information about the transaction status See Transaction Processing.
Example: Host declined the transaction