parent
ac30d228ca
commit
7f96ab14a4
@ -0,0 +1,25 @@
|
||||
package com.example.wfwebapi.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<String> handleAllExceptions(Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred : " + ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(NullPointerException.class)
|
||||
public ResponseEntity<String> handleNullPointerException(NullPointerException ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Null pointer exception caught : " + ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(ResourceNotFoundException.class)
|
||||
public ResponseEntity<String> handleResourceNotFoundException(ResourceNotFoundException ex) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Resource not found : " + ex.getMessage());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue