com.amazonaws.serverless.proxy.spring.SpringAwsProxyExceptionHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-serverless-java-container-spring Show documentation
Show all versions of aws-serverless-java-container-spring Show documentation
Allows Java applications written for the Spring framework to run in AWS Lambda
The newest version!
package com.amazonaws.serverless.proxy.spring;
import com.amazonaws.serverless.proxy.AwsProxyExceptionHandler;
import com.amazonaws.serverless.proxy.ExceptionHandler;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import org.springframework.web.ErrorResponse;
/**
* This ExceptionHandler implementation enhances the standard AwsProxyExceptionHandler
* by mapping additional details from org.springframework.web.ErrorResponse
*/
public class SpringAwsProxyExceptionHandler extends AwsProxyExceptionHandler
implements ExceptionHandler {
@Override
public AwsProxyResponse handle(Throwable ex) {
if (ex instanceof ErrorResponse) {
return new AwsProxyResponse(((ErrorResponse) ex).getStatusCode().value(),
HEADERS, getErrorJson(ex.getMessage()));
} else {
return super.handle(ex);
}
}
}