aboutsummaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java')
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java28
1 files changed, 13 insertions, 15 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java b/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
index 4b3515b..452815e 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
@@ -43,39 +43,37 @@ import com.sun.istack.SAXParseException2;
@Provider
public class ExceptionHandler implements ExceptionMapper<Exception> {
+ private static final String AAI_4007 = "AAI_4007";
+
@Context
private HttpServletRequest request;
@Context
private HttpHeaders headers;
- /**
- * @{inheritDoc}
- */
@Override
public Response toResponse(Exception exception) {
Response response = null;
- ArrayList<String> templateVars = new ArrayList<String>();
+ ArrayList<String> templateVars = new ArrayList<>();
//the general case is that cxf will give us a WebApplicationException
//with a linked exception
if (exception instanceof WebApplicationException) {
WebApplicationException e = (WebApplicationException) exception;
- if (e.getCause() != null) {
- if (e.getCause() instanceof SAXParseException2) {
- templateVars.add("UnmarshalException");
- AAIException ex = new AAIException("AAI_4007", exception);
- response = Response
- .status(400)
- .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
- .build();
- }
+ if (e.getCause() instanceof SAXParseException2) {
+ templateVars.add("UnmarshalException");
+ AAIException ex = new AAIException(AAI_4007, exception);
+ response = Response
+ .status(400)
+ .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
+ .build();
+
}
} else if (exception instanceof JsonParseException) {
//jackson does it differently so we get the direct JsonParseException
templateVars.add("JsonParseException");
- AAIException ex = new AAIException("AAI_4007", exception);
+ AAIException ex = new AAIException(AAI_4007, exception);
response = Response
.status(400)
.entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
@@ -83,7 +81,7 @@ public class ExceptionHandler implements ExceptionMapper<Exception> {
} else if (exception instanceof JsonMappingException) {
//jackson does it differently so we get the direct JsonParseException
templateVars.add("JsonMappingException");
- AAIException ex = new AAIException("AAI_4007", exception);
+ AAIException ex = new AAIException(AAI_4007, exception);
response = Response
.status(400)
.entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))