use of core.framework.web.service.RemoteServiceException in project core-ng-project by neowu.
the class WebServiceClientTest method validateResponseWithErrorResponse.
@Test
void validateResponseWithErrorResponse() {
ErrorResponse response = new ErrorResponse();
response.severity = "WARN";
response.errorCode = "NOT_FOUND";
response.message = "not found";
RemoteServiceException exception = assertThrows(RemoteServiceException.class, () -> webServiceClient.validateResponse(new HTTPResponse(HTTPStatus.NOT_FOUND, Maps.newHashMap(), Strings.bytes(JSON.toJSON(response)))));
assertEquals(Severity.WARN, exception.severity());
assertEquals(response.errorCode, exception.errorCode());
assertEquals(response.message, exception.getMessage());
}
use of core.framework.web.service.RemoteServiceException in project core-ng-project by neowu.
the class WebServiceClient method validateResponse.
void validateResponse(HTTPResponse response) {
HTTPStatus status = response.status();
if (status.code >= 200 && status.code < 300)
return;
byte[] responseBody = response.body();
try {
ErrorResponse error = JSONMapper.fromJSON(ErrorResponse.class, responseBody);
logger.debug("failed to call remote service, id={}, severity={}, errorCode={}, remoteStackTrace={}", error.id, error.severity, error.errorCode, error.stackTrace);
throw new RemoteServiceException(error.message, parseSeverity(error.severity), error.errorCode);
} catch (RemoteServiceException e) {
throw e;
} catch (Throwable e) {
String responseText = response.text();
logger.warn("failed to decode response, statusCode={}, responseText={}", status.code, responseText, e);
throw new RemoteServiceException(Strings.format("internal communication failed, status={}, responseText={}", status.code, responseText), Severity.ERROR, "REMOTE_SERVICE_ERROR", e);
}
}
Aggregations