Questions tagged [controller-advice]
70 questions
8
votes
3 answers
Spring boot Rest responding with empty body for exceptions other than the ones overridden in my @ControllerAdvice
I have a @ControllerAdvice extending ResponseEntityExceptionHandler as an attempt for me to control standard response for any exception raised with in the API call workflow.
Without the Controller advice. I get HTML based generic response generated…
Gagandeep Singh
- 81
- 1
- 2
7
votes
3 answers
@ControllerAdvice and @ExceptionHandler not getting triggered for my RestController
In order to have unified exception handling throughout the application I am using Error Handling for REST with Spring solution#3 which uses @ControllerAdvice along with @ExceptionHandler.
Spring version: 4.3.22.RELEASE
Spring Boot version:…
Learner
- 1,285
- 3
- 18
- 34
5
votes
1 answer
How to pass checked exception from CompletableFuture to ControllerAdvice
How can I make the controllerAdvice class catch the exception that is thrown from completablefutrue.
In the code below I have a method checkId that throws a checked exception. I call this method using completablefuture and wrap the checked…
MoA
- 458
- 4
- 20
4
votes
0 answers
How to use @ControllerAdvice if there is no HTTP body?
I'd like to have an @ControllerAdvice that is called for all HTTP requests on all controllers. Unfortunately it only triggers if there is a HTTP body in the request. If not, it's completely ignored. Isn't spring supposed to call handleEmptyBody() in…
BetaRide
- 14,756
- 26
- 84
- 153
3
votes
1 answer
Java Test for Spring ExceptionalHandler
I have a springboot project with controllers and servies. And a GlobalExceptionHandler like -
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(DataIntegrityViolationException.class)
public…
Akanksha
- 151
- 2
- 7
3
votes
1 answer
How to extract the field name and the error message from the MethodArgumentNotValidException class?
I am using javax.validation.Size annotation to perform String size validation.
@Data
public class EventRequestBean {
@Size( max = 40 )
private String title;
@Size( max = 50 )
private String topic;
}
And I am using a global…
Naanavanalla
- 1,119
- 2
- 16
- 40
2
votes
1 answer
When to use ResponseStatusException and ControllerAdvice
Spring5 has introduced ResponseStatusException, which has put me in a dilemma as to in what scenario I can use a ResponseStatusException and ControllerAdvice as both of them are quiet similar.
Can anyone help me with this.
Thanks in advance.
Sonali
- 43
- 5
2
votes
2 answers
How do I change only the status code on a Spring MVC error with Boot?
I'm writing a Web application that makes downstream calls using RestTemplate. If the underlying service returns a 401 Unauthorized, I want to also return a 401 to the calling application; the default behavior is to return a 500. I want to keep the…
chrylis -cautiouslyoptimistic-
- 67,584
- 19
- 106
- 140
2
votes
2 answers
ControllerAdvice conditionally handle exception
I have a controller advice that handles the exceptional behavior in my REST controller and I came across a situation when I have to conditionally process SQLIntegrityConstraintViolationException that have a certain message (the one for duplicate…
Daniel Pop
- 175
- 1
- 12
2
votes
1 answer
Spring Boot @ControllerAdvice / @Valid
I am working on sample demo application for Exception Handling in Spring Boot.I am trying Exception Handling With @ControllerAdvice.
I would like to handle exception thrown by validator. It handles other exceptions but not…
Airam
- 21
- 3
2
votes
0 answers
How to catch all the exceptions in Spring boot 2 webflux with @ControllerAdvice
My application is made by Spring Boot 2 webflux and thymeleaf, I want to catch all the exception and render the error to a customized error page.
I use @ControllerAdvice and @ExceptionHandler to catch exceptions and handle errors in a central…
user2592010
- 21
- 3
2
votes
1 answer
How to capture the response of ResponseEntityExceptionHandler to create JWE encrypt
I have springboot based restful web-service. I have CryptoResponseBodyAdvice to capture the response from controller and create JWE out of response body and send JWE as API response.
public class CryptoResponseBodyAdvice implements…
Ashish Garg
- 21
- 1
2
votes
2 answers
What order value do I use on a ControllerAdvice if my libraries may also have ControllerAdvices with Order annotations that I do not know about?
I have a Spring 4 application with multiple ControllerAdvices annotated with @Order(someValue). In addition, I have discovered a ControllerAdvice in one of my external libraries also annotated with @Order(someValue).
My understanding is that when a…
Denise Salazar
- 23
- 4
2
votes
1 answer
Spring Boot Controller Advice - How to return XML instead of JSON?
I have a controller advice class, but I can't seem to get it to return XML, even though I've used the @RequestMapping annotation. Here's a stripped-down example.
@RestControllerAdvice
public class ControllerAdvice {
…
geekTechnique
- 637
- 1
- 8
- 28
1
vote
0 answers
Spring Web: ControllerAdvice
I have the simple class to catch some exceptions like this:
@ControllerAdvice
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(RuntimeException.class)
public ResponseEntity
MrLebovsky
- 58
- 7