File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed
src/main/java/org/gridsuite/useradmin/server Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change 18
18
*/
19
19
@ ControllerAdvice
20
20
public class RestResponseEntityExceptionHandler {
21
-
22
21
@ ExceptionHandler (value = { UserAdminException .class })
23
22
protected ResponseEntity <Object > handleException (RuntimeException exception ) {
24
- if (exception instanceof UserAdminException ) {
25
- UserAdminException userAdminException = (UserAdminException ) exception ;
26
- if (userAdminException .getType ().equals (FORBIDDEN )) {
27
- return ResponseEntity .status (HttpStatus .FORBIDDEN ).body (userAdminException .getType ());
28
- }
23
+ if (exception instanceof UserAdminException userAdminException ) {
24
+ return switch (userAdminException .getType ()) {
25
+ case FORBIDDEN -> ResponseEntity .status (HttpStatus .FORBIDDEN ).body (userAdminException .getType ());
26
+ };
27
+ } else {
28
+ return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).build ();
29
29
}
30
- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).build ();
31
30
}
32
31
}
Original file line number Diff line number Diff line change 6
6
*/
7
7
package org .gridsuite .useradmin .server ;
8
8
9
+ import lombok .Data ;
10
+ import lombok .EqualsAndHashCode ;
11
+
9
12
import java .util .Objects ;
10
13
11
14
/**
12
15
* @author Etienne Homer <etienne.homer at rte-france.com>
13
16
*/
17
+ @ EqualsAndHashCode (callSuper = false )
18
+ @ Data
14
19
public class UserAdminException extends RuntimeException {
15
20
public enum Type {
16
21
FORBIDDEN
@@ -22,9 +27,4 @@ public UserAdminException(Type type) {
22
27
super (Objects .requireNonNull (type .name ()));
23
28
this .type = type ;
24
29
}
25
-
26
- Type getType () {
27
- return type ;
28
- }
29
-
30
30
}
You can’t perform that action at this time.
0 commit comments