use of com.linkedin.restli.common.ErrorDetails in project rest.li by linkedin.
the class ErrorResponseBuilder method buildErrorResponse.
private ErrorResponse buildErrorResponse(RestLiServiceException result, ErrorResponseFormat errorResponseFormat) {
ErrorResponse er = new ErrorResponse();
if (errorResponseFormat.showStatusCodeInBody()) {
er.setStatus(result.getStatus().getCode());
}
if (errorResponseFormat.showMessage() && result.getMessage() != null) {
er.setMessage(result.getMessage());
}
if (errorResponseFormat.showServiceErrorCode() && result.hasServiceErrorCode()) {
er.setServiceErrorCode(result.getServiceErrorCode());
}
if (errorResponseFormat.showDetails() && result.hasErrorDetails()) {
er.setErrorDetails(new ErrorDetails(result.getErrorDetails()));
}
if (errorResponseFormat.showStacktrace()) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
result.printStackTrace(pw);
er.setStackTrace(sw.toString());
er.setExceptionClass(result.getClass().getName());
}
if (errorResponseFormat.showExceptionClass()) {
er.setExceptionClass(result.getClass().getName());
}
return er;
}
use of com.linkedin.restli.common.ErrorDetails in project rest.li by linkedin.
the class ParSeqRestClientTest method mockClient.
/**
* @return a mock ParSeqRestClient that gives an error
*/
private ParSeqRestClient mockClient(final String errKey, final String errValue, final String errMsg, final int httpCode, final int appCode, final ProtocolVersion protocolVersion, final String errorResponseHeaderName) {
final ErrorResponse er = new ErrorResponse();
final DataMap errMap = new DataMap();
errMap.put(errKey, errValue);
er.setErrorDetails(new ErrorDetails(errMap));
er.setStatus(httpCode);
er.setMessage(errMsg);
er.setServiceErrorCode(appCode);
final byte[] mapBytes;
try {
mapBytes = new JacksonDataCodec().mapToBytes(er.data());
} catch (final IOException e) {
throw new RuntimeException(e);
}
final Map<String, String> headers = new HashMap<>();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
headers.put(errorResponseHeaderName, RestConstants.HEADER_VALUE_ERROR);
return new ParSeqRestClient(new RestClient(new MockClient(httpCode, headers, mapBytes), "http://localhost"), RequestConfigProvider.build(new ParSeqRestliClientConfigBuilder().build(), () -> Optional.empty()));
}
use of com.linkedin.restli.common.ErrorDetails in project rest.li by linkedin.
the class RestClientTest method mockClient.
private RestClient mockClient(String errKey, String errValue, String errMsg, int httpCode, int appCode, ProtocolVersion protocolVersion, String errorResponseHeaderName) {
ErrorResponse er = new ErrorResponse();
DataMap errMap = new DataMap();
errMap.put(errKey, errValue);
er.setErrorDetails(new ErrorDetails(errMap));
er.setStatus(httpCode);
er.setMessage(errMsg);
er.setServiceErrorCode(appCode);
byte[] mapBytes;
try {
mapBytes = new JacksonDataCodec().mapToBytes(er.data());
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, String> headers = new HashMap<String, String>();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
headers.put(errorResponseHeaderName, RestConstants.HEADER_VALUE_ERROR);
return new RestClient(new MyMockClient(httpCode, headers, mapBytes), "http://localhost");
}
Aggregations