@Override
public void onComplete(HyperionContext context)
{
EndpointResponse response = context.getEndpointResponse();
Throwable error = context.getError();
if(error != null)
{
Throwable cause = getCause(error);
int status = 500;
if(error instanceof HyperionException)
{
status = ((HyperionException)error).getStatusCode();
}
if(status == 500)
logger.error(cause.getMessage(),cause);
else
logger.info(cause.getMessage());
if(!context.isTimedOut())
{
response.setResponseCode(status);
response.setContentEncoding("UTF-8");
response.setContentType("application/json");
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setStatusCode(response.getResponseCode());
errorResponse.setMessage(error.getMessage());
if (status == 500 || context.getShowErrorDetail())
errorResponse.setStackTrace(buildStackTrace(cause));
String exceptionType = error.getClass().getName();
if (!(error instanceof HyperionException))
exceptionType = InternalException.class.getName();
else
errorResponse.setErrorDetails(((HyperionException) error).getErrorDetails());
errorResponse.setType(exceptionType);
endpointMarshaller.marshall(response.getOutputStream(), errorResponse);
}
}
}