private Mono<Void> error(HttpServerResponse httpResponse, ServiceMessage response) { int code = response.errorType(); HttpResponseStatus status = HttpResponseStatus.valueOf(code); ByteBuf content = response.hasData(ErrorData.class) ? encodeData(response.data(), response.dataFormatOrDefault()) : response.data(); return httpResponse.status(status).sendObject(content).then(); }
@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); } }