diff options
author | David Brilla <david.brilla@tieto.com> | 2020-04-21 13:53:51 +0200 |
---|---|---|
committer | David Brilla <david.brilla@tieto.com> | 2020-04-23 10:57:18 +0200 |
commit | a63c0041198389ce55b3d66e746591ffe3eea1fe (patch) | |
tree | dc5404f5bd86d5abd4dd6c712505b34d0af4ff7b /aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java | |
parent | 87f84fdb2df41aa7c00de94018fe606939d4d6f7 (diff) |
Sonar fixes
Issue-ID: AAI-2877
Change-Id: Ida4f641c4cc87b69ba5d0ae2c7f3804e53af5b68
Signed-off-by: David Brilla <david.brilla@tieto.com>
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.java | 28 |
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)) |