Commit a87a4c5 ecureuill
committed
1 parent a584815 commit a87a4c5 Copy full SHA for a87a4c5
File tree 1 file changed +27
-0
lines changed
src/main/java/ecureuill/milhasapi/infra/expection
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ package ecureuill .milhasapi .infra .expection ;
2
+
3
+ import org .springframework .http .ResponseEntity ;
4
+ import org .springframework .web .bind .annotation .ExceptionHandler ;
5
+ import org .springframework .web .bind .annotation .RestControllerAdvice ;
6
+ import org .springframework .web .server .ResponseStatusException ;
7
+
8
+ import jakarta .persistence .EntityNotFoundException ;
9
+
10
+ @ RestControllerAdvice
11
+ public class ControllerAdvice {
12
+
13
+ @ ExceptionHandler (value = EntityNotFoundException .class )
14
+ public ResponseEntity <String > handleEntityNotFoundException (EntityNotFoundException e ) {
15
+ return ResponseEntity .notFound ().build ();
16
+ }
17
+
18
+ @ ExceptionHandler (value = ResponseStatusException .class )
19
+ public ResponseEntity <String > handleResponseStatusException (ResponseStatusException ex ) {
20
+ return ResponseEntity .status (ex .getStatusCode ()).body (ex .getReason ());
21
+ }
22
+
23
+ @ ExceptionHandler (value = Exception .class )
24
+ public ResponseEntity <String > handleException (Exception e ) {
25
+ return ResponseEntity .badRequest ().body (e .getMessage ());
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments