@Override public Throwable toError(ServiceMessage message) { ErrorData data = message.data(); int errorType = message.errorType(); int errorCode = data.getErrorCode(); String errorMessage = data.getErrorMessage(); switch (errorType) { case BadRequestException.ERROR_TYPE: return new BadRequestException(errorCode, errorMessage); case UnauthorizedException.ERROR_TYPE: return new UnauthorizedException(errorCode, errorMessage); case ServiceUnavailableException.ERROR_TYPE: return new ServiceUnavailableException(errorCode, errorMessage); case InternalServiceException.ERROR_TYPE: return new InternalServiceException(errorCode, errorMessage); // Handle other types of Service Exceptions here default: return new InternalServiceException(errorCode, errorMessage); } }
@Override public Throwable toError(ClientMessage message) { ErrorData errorData = message.data(); int errorType = message.errorType(); int errorCode = errorData.getErrorCode(); String errorMessage = errorData.getErrorMessage(); switch (errorType) { case BadRequestException.ERROR_TYPE: return new BadRequestException(errorCode, errorMessage); case UnauthorizedException.ERROR_TYPE: return new UnauthorizedException(errorCode, errorMessage); case ServiceUnavailableException.ERROR_TYPE: return new ServiceUnavailableException(errorCode, errorMessage); case InternalServiceException.ERROR_TYPE: return new InternalServiceException(errorCode, errorMessage); // Handle other types of Service Exceptions here default: return new InternalServiceException(errorCode, errorMessage); } } }