Questions tagged [controller-advice]
113 questions
0
votes
1 answer
ExceptionHandler doesn't catch HandlerInterceptor exception if endpoint path is unknown
I have a component that implements the HandlerInterceptor interface, and implements the preHandle method. In this method I retrieve a parameter from the request, and throw an IllegalArgumentException if that parameter is missing.
@Override
…

Christophe Schutz
- 605
- 4
- 19
0
votes
1 answer
I can't catch NumberFormatException in spring boot api rest
this problem has me crazy and I don't know where to look anymore.
I have a rest api that receives a @RequestBody DTO
public ResponseEntity edit(@Valid @RequestBody JuntaCalificadoraDTO juntaCalifDTO) {
......
This is the DTO…

brujita
- 31
- 3
0
votes
1 answer
@ControllerAdvice to handle different url error
I am making 2 API calls:
Response result1 = restTemplate.postForObject(api1url, data1, Response.class);
Response result2 = restTemplate.postForObject(api2url, data2, Response.class);
I am using @RestControllerAdvice to handle the error if any…

norulshahlam mohsen
- 33
- 6
0
votes
0 answers
Exception the exception thrown from Stream.forEach() in ControllerAdvice
In my Spring MVC Based application, I have a ControllerAdvice defined.
Now, in one of my service classes, I have this parallelStream created:
rawImportList.parallelStream().forEach(rawImportBatch -> {
…

Curious Coder
- 646
- 8
- 18
0
votes
0 answers
ControllerAdvice is not able to catch exception being thrown from an interceptor middleware
So we have implemented an interceptor middleware in java spring boot. The intention is to use this middleware in any client application (rest api clients) and validate all incoming http requests to prevent any CSRF attack. We are using this…

Dhiren
- 428
- 1
- 3
- 12
0
votes
1 answer
How to throw NoHandlerFoundException if path param is not Long in springboot
Currently, there is a GetMapping like follows
@GetMapping(value = "/{id}")
public ResponseEntity getTrainById(@PathVariable Long id) {
Dog dog= animalService.getAnimalById(id);
return new ResponseEntity<>(Dog , HttpStatus.OK);
…

Jayamal Jayamaha
- 197
- 2
- 14
0
votes
0 answers
Catching ValidationException instead of a custom Exception in ControllerAdvice
I'm trying to throw an exception inside a custom validator which I built using annotation like that:
ValidExtractionDate annotation:
@Constraint(validatedBy = ExtractionDateValidator.class)
@Target( { ElementType.PARAMETER…

mr.Penguin
- 1,166
- 1
- 8
- 24
0
votes
1 answer
spring boot @ExceptionHandler not catching exceptions throwed in @Aspect classes
I have an aspect class that log executions of methods before and after (around) using a generic method :
@Aspect
@Component
public class LoggingAspect {
@Around("com.obs.dqsc.api.config.AspectConfig.allLayers()")
public Object…

mr.Penguin
- 1,166
- 1
- 8
- 24
0
votes
1 answer
Java Spring ExceptionHandler Controller syntax and good practices
I would like to handle my exceptions correctly in Spring, so I have a question about exceptionHandler syntax : Is it ok to throw specific exceptions in the controller, if they are caught by the exception handler ?
More specifically :
Here is the…

FloranePlo
- 59
- 8
0
votes
2 answers
Custom - ConstraintViolationException - SQL Exception
I have a custom advice to handle exceptions from controllers copied from REST API Error Handling and a method to handle DataIntegrityViolationException:
@ExceptionHandler(DataIntegrityViolationException.class)
protected ResponseEntity

Aldo Inácio da Silva
- 824
- 2
- 14
- 38
0
votes
1 answer
Spring Boot Rest Controller endpoint exception: HttpMediaTypeNotAcceptableException
I am experiencing an issue while a mandatory field is not filled, the following exception is displayed in the logs:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
Lets say I have an object…

user1999453
- 1,297
- 4
- 29
- 65
0
votes
0 answers
: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource
I am handling exceptions for HttpRequestMethodNotSupportedException.class and
MethodArgumentTypeMismatchException.class
I am using @ExceptionHandler annotation in @ControllerAdvice Class but when I try to use handle both exceptions and write two…

Ajay Shewale
- 1
- 1
0
votes
1 answer
Is it possible to have mapping between rest controller and controller advice in spring boot 2.4.4 rest java 11 application?
I have a spring boot 2.4.4 java 11 application with many Rest Controllers. I am using @ControllerAdvice for handling all exceptions including custom exceptions.
Is there anyway to map or identify which controller is involved at the time of…

KJ21
- 63
- 7
0
votes
1 answer
Java object with Lombok not working inside point cut annotated classes in spring boot
I have the following DTO object used in Java spring boot code.
ExceptionResponseDTO.java
package be.bytebrain.hrms.exception;
import java.time.LocalDateTime;
import lombok.Data;
@Data
public class ExceptionResponseDTO {
private String…

Naveen Vignesh
- 1,351
- 10
- 21
0
votes
0 answers
ControllerAdvice not handling certain exceptions
After a few days browsing i didn't find a solution so I thought i'd post.
Right away, sorry for my english.
I'm trying to get custom exceptions from a backend running in Java with Jhipster's stack of technology (Spring MVC, JPA, etc...) to my…

Jeremy Carruba
- 1
- 1