Handling Errors - AEVI-AppFlow/pos-android-sdk GitHub Wiki
Flow errors can come in via two channels;
- Initiation rx stream
onError
- Response listener
notifyError
Initiation errors
When FPS receives a request, it will perform a range of validation on it and any associated flow, as well as ensure that it is currently able to process the request. Any subscriber to the initiate methods must ensure to add a consumer for any Throwable
, as per below. All exceptions thrown by AppFlow will be of type FlowException
, but it is of course possible that unexpected exceptions can occur as well.
paymentClient.initiatePayment(payment).subscribe(() -> {
// Request accepted
}, throwable -> {
if (throwable instanceof FlowException) {
FlowException flowException = (FlowException) throwable;
handleFlowError(flowException.getErrorCode());
Log.e(TAG, "Flow error: " + flowException.getErrorMessage());
} else {
// Handle unexpected exception
}
});
The flowException.getErrorCode()
returns a code that can be mapped against the constants in ErrorConstants
, part of the API. See the table below for possible error codes for the initiation stage.
Error code | Error description |
---|---|
notInstalled | Sent if the processing service (FPS) is not installed on the device |
busy | Sent if the processing service (FPS) is already processing a request |
unsupportedOperation | Sent if an unsupported flow/request type/name is sent to the processing service |
multipleConfigProviders | Sent if there is more than one configuration provider installed on the device |
noConfigProvider | Sent if there is no configuration provider installed on the device |
incompatibleApiVersion | Sent if the client is integrated with a different major API version than the processing service |
invalidRequest | Sent if the request was malformed or failed validation |
missingResponseListener | Sent if the client has not defined the relevant response listeners |
invalidMessageType | Sent in the (rare case) that the message received is invalid or unknown |
cancelFailed | Sent in the (rare case) where the processing service failed to cancel a flow as requested by merchant |
resumeFailed | Sent if the (rare case) where the processing service failed to resume a flow as requested by merchant |
Response listener errors
Once FPS has accepted your request, it will complete the initiation stream and start processing the flow. After this point, if any errors occur, they will be sent back via the response listener notifyError
method. Most outcomes at this point will lead to an actual PaymentResponse
or Response
being generated with relevant outcomes set, but in rare cases the flow can abruptly end due to misbehaving flow services, device problems, etc. The errors are sent back to the method signature as per below;
@Override
protected void notifyError(String errorCode, String errorMessage) {}
In this case, the error code and message have been extracted from the FlowException
and passed directly to the listener. The following error codes are relevant for the response listener. See ErrorConstants
in the API for defined values.
Error code | Error description |
---|---|
flowServiceError | A general purpose error that will be sent for fatal failures in a flow service |
stageNotSupported | Sent if a flow service does not support the stage it has just been called for |
configError | Sent if the processing service cannot find a handler(s) for a stage |
unexpectedError | Something unexpected happened |