use of com.liferay.apio.architect.functional.Try.Failure in project com-liferay-apio-architect by liferay.
the class FailureFilter method filter.
@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
Try<Object> objectTry = Try.fromFallible(containerResponseContext::getEntity);
objectTry.map(Failure.class::cast).map(Failure::getException).map(exception -> _errorUtil.getErrorResponse(exception, _request, _httpHeaders)).ifSuccess(response -> {
containerResponseContext.setStatus(response.getStatus());
MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();
headers.remove(CONTENT_TYPE);
MediaType mediaType = response.getMediaType();
if (mediaType != null) {
headers.add(CONTENT_TYPE, mediaType.toString());
}
Object entity = response.getEntity();
if (entity != null) {
containerResponseContext.setEntity(entity);
}
});
}
Aggregations