powerauth-server
powerauth-server copied to clipboard
Revise and rewrite error handling
Since we prioritize REST over SOAP in recent releases, we do not need to limit ourselves to the constraints that were enforced by the SOAP Fault approach. We should review and rewrite the error handling to more standard approaches.
Just to provide an insight into this issue, this is how the current error handling looks like:
try {
// ...
} catch (PowerAuthClientException e) {
final PowerAuthError error = e.getPowerAuthError();
switch (error.getCode()) {
case "ERR0034": {
throw new OperationNotFoundException("Operation with given ID was not found");
}
case "ERR0036": {
logger.error("Trying to cancel operation that cannot be canceled: {}", e.getMessage());
throw new OperationStateException("Operation is in invalid state for requested action");
}
default: {
logger.error("Calling PowerAuth service failed: {}", e.getMessage());
logger.debug("Exception detail:", e);
throw new RegistrationFailedException("Unable to call upstream service");
}
}
}
=> Error codes are weakly typed. => Error codes do not have a descriptive name. => Error codes are not scoped - theoretically, you would need to handle all ~40 of them in every call.