Questions tagged [controller-advice]

113 questions
0
votes
0 answers

Spring is not catching 403 error in global exception handler

I am a very beginner in spring. In my application, I created a global exception handler class using @ControllerAdvice. It is catching all 5xx errors. But when it is getting some 403 error, it is showing the default page. My calls file is package…
Arun
  • 3,640
  • 7
  • 44
  • 87
0
votes
0 answers

How to handle a BindException thrown by @Valid annotation using a controller advice which extends ResponseEntityExceptionHandler?

I have a @NotNull validation for some fields in a POJO which represents my request params: Endpoint: public ResponseEntity initializeLaunchPost(@Valid OidcFlowInitRequest request) throws LtiValidationException { Request…
0
votes
1 answer

@RestContollerAdvice not throwing custom exception

I am using Spring Boot 3 to develop a simple Rest API and want to handle exceptions using @RestControllerAdvice, but my code is throwing a 500 error even if the code in @exceptionHandler is throwing a 404 error code. I verified in debugging that…
0
votes
0 answers

Wrapped Response by ResponseBodyAdvice in Spring Boot not showing up in Swagger. Any idea how could it be done?

@ControllerAdvice public class CA implements ResponseBodyAdvice { } This class will wrap the response @GetMapping public Person getPerson() { return new Person(); } In Swagger I want it to show WrappedResponse but instead it shows…
0
votes
0 answers

Failure in Custom Exception Handler for HttpMediaTypeNotAcceptableException

I'm trying to add a custom Exception handler, which can add a more understandable response to my Spring Boot Rest API, whenever a person uses wrong Accept: Headers. Looking at my logs, the DefaultExceptionhandler resolves the following: Resolved…
Lukas
  • 1
0
votes
0 answers

Kotlin: Spring ExceptionHandler Not Working When Validating RequestBody

It seems I cannot get my @ControllerAdvice to work with Kotlin POJOs. Note, it works when I throw an exception and with path params but doesn't work when validating the body of a request. ControllerAdvice @ControllerAdvice class ExceptionAdvice :…
0
votes
0 answers

How to convert SpringBoot2x request return xml type to json type?

Due to some reasons, A colleague calling my interface request header accept does not carry an application/json parameter accept:text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 add @PostMapping(value = "**",produces = {"application/json"}) at…
0
votes
0 answers

@ExceptionHandler for Exception.class, the exception message is null on graalVM native image

Have this code inside ControllerAdvice: @ExceptionHandler(value = Exception.class) @ResponseStatus(value = INTERNAL_SERVER_ERROR) protected ResponseEntity handleAnyException(Exception ex, WebRequest request) { for custom exception and…
xMilos
  • 1,519
  • 4
  • 21
  • 36
0
votes
0 answers

@PathVariable annotated variable contains wrong value in conjunction with @ControllerAdvice & StringEditor (PropertyEditor) - SpringMVC

When using a @ControllerAdvice and having a MVC-Controller with a GET-Mapping that has a path variable, this path variable is sometimes assigned a wrong value when used in concurrent requests. The original function of the controller method in…
0
votes
2 answers

Spring-Boot:How to get all request body in WebRequest

Is it possible to fetch RequestBody from WebRequest object? I am handling exceptions from controller advice so would like to handle the request as well to send data back in response. I saw its documentation what I understood is we can fetch query…
Loren
  • 320
  • 1
  • 10
  • 25
0
votes
0 answers

How to separate Controller and HandlerInterceptor exception?

Sample interceptor code package com.my.interceptor; public class MyInterceptor implements HandlerInterceptor { @Override public boolean preHandle( ... ) throws Exception { throw new Exception("test exception"); // throw test exception …
Rurien
  • 359
  • 1
  • 13
0
votes
1 answer

After an exception is thrown (handled by controller advice), will the globally executed aop program also terminate?

controller: @RestController @RequestMapping("/test") public class TestController { /** * @RequestLog records logs annotation */ @PostMapping("/t1") @RequestLog(description = "log test") public ApiResult t1(@RequestBody…
sk w
  • 19
  • 6
0
votes
1 answer

Exceptionhandler for Enum in request parameter

I have a Get request: \allTopic It inputs a filterCriteria custom object which contains multiple fields and one of those is an Enum called Role, which is either student or teacher And there are many more different API calls with different Enums. So…
Nagulan S
  • 617
  • 5
  • 11
0
votes
1 answer

Multiple rest advisor in spring boot based on API path

I have a spring boot application currently in production. It has APIs which return the error in this format { "success": true, "error": "Error message" } This error response I'm handling through the controller advisor. I'm creating v2 APIs…
0
votes
0 answers

How to apply @ControllerAdvice from a non-controller?

Is there a way in which we can generate the JSON response from within the code that an API endpoint would show when a controller is called. I basically want the application to call one of its own controllers and generate the response as a JSON…
Saif
  • 2,530
  • 3
  • 27
  • 45