From 46c9d85cce3ec02be21d0ab657b7758ecff3d342 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Wed, 5 Jul 2023 15:43:15 +0200 Subject: [PATCH] style: fix import, white-space and sonar lint issues --- .../ors/api/controllers/RoutingAPI.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ors-api/src/main/java/org/heigit/ors/api/controllers/RoutingAPI.java b/ors-api/src/main/java/org/heigit/ors/api/controllers/RoutingAPI.java index d7b8916e77..f02eef33cd 100644 --- a/ors-api/src/main/java/org/heigit/ors/api/controllers/RoutingAPI.java +++ b/ors-api/src/main/java/org/heigit/ors/api/controllers/RoutingAPI.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -48,7 +47,7 @@ import javax.servlet.http.HttpServletResponse; - @RestController +@RestController @Tag(name = "Directions Service", description = "Get directions for different modes of transport") @RequestMapping("/v2/directions") @ApiResponse(responseCode = "400", description = "The request is incorrect and therefore can not be processed.") @@ -214,16 +213,16 @@ public ResponseEntity handleMissingParams(final MissingServletRequestPar @ExceptionHandler({HttpMessageNotReadableException.class, ConversionFailedException.class, HttpMessageConversionException.class, Exception.class}) public ResponseEntity handleReadingBodyException(final Exception e) { final Throwable cause = e.getCause(); - if (cause instanceof UnrecognizedPropertyException) { - return errorHandler.handleUnknownParameterException(new UnknownParameterException(RoutingErrorCodes.UNKNOWN_PARAMETER, ((UnrecognizedPropertyException) cause).getPropertyName())); - } else if (cause instanceof InvalidFormatException) { - return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_FORMAT, "" + ((InvalidFormatException) cause).getValue())); - } else if (cause instanceof ConversionFailedException) { - return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, "" + ((ConversionFailedException) cause).getValue())); - } else if (cause instanceof InvalidDefinitionException) { - return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, ((InvalidDefinitionException) cause).getPath().get(0).getFieldName())); - } else if (cause instanceof MismatchedInputException) { - return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_FORMAT, ((MismatchedInputException) cause).getPath().get(0).getFieldName())); + if (cause instanceof UnrecognizedPropertyException exception) { + return errorHandler.handleUnknownParameterException(new UnknownParameterException(RoutingErrorCodes.UNKNOWN_PARAMETER, exception.getPropertyName())); + } else if (cause instanceof InvalidFormatException exception) { + return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_FORMAT, "" + exception.getValue())); + } else if (cause instanceof ConversionFailedException exception) { + return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, "" + exception.getValue())); + } else if (cause instanceof InvalidDefinitionException exception) { + return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, exception.getPath().get(0).getFieldName())); + } else if (cause instanceof MismatchedInputException exception) { + return errorHandler.handleStatusCodeException(new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_FORMAT, exception.getPath().get(0).getFieldName())); } else { // Check if we are missing the body as a whole if (e.getLocalizedMessage().startsWith("Required request body is missing")) {