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")) {