Skip to content

s2agrahari/global-exception-handler-spring-boot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

global-excpetion-handler-spring-boot

Global Exception Handler in Spring Boot

Create a controller advice in your project as below to Globally Handle Exceptions and return your own custom error object

@ControllerAdvice public class GlobalErrorHandler extends ResponseEntityExceptionHandler {

@ExceptionHandler(value = {CustomException.class})
protected ResponseEntity<Object> handleInvalidDataException(
        RuntimeException ex, WebRequest request) {
    return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
}

}

About

Global Exception Handler in Spring Boot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published