|
6 | 6 | import org.springframework.http.ResponseEntity;
|
7 | 7 | import org.springframework.web.bind.annotation.ControllerAdvice;
|
8 | 8 | import org.springframework.web.bind.annotation.ExceptionHandler;
|
9 |
| - |
10 |
| -import java.util.Arrays; |
| 9 | +//import java.util.Arrays; |
11 | 10 |
|
12 | 11 | @ControllerAdvice
|
13 | 12 | public class ExceptionHandlerController extends BaseController {
|
| 13 | + @ExceptionHandler(BadRequestException.class) |
| 14 | + public ResponseEntity<Object> handleBadRequestException(BadRequestException e) { |
| 15 | + ResponseDTO response = this.responseMapper.toDTO( |
| 16 | + 400, |
| 17 | + e.getMessage(), |
| 18 | + null |
| 19 | + ); |
| 20 | + |
| 21 | + return ResponseEntity.status(400).body(response); |
| 22 | + } |
| 23 | + |
| 24 | + @ExceptionHandler(UnauthorizedException.class) |
| 25 | + public ResponseEntity<Object> handleUnauthorizedException(UnauthorizedException e) { |
| 26 | + |
| 27 | + ResponseDTO response = this.responseMapper.toDTO( |
| 28 | + 403, |
| 29 | + e.getMessage(), |
| 30 | + null |
| 31 | + ); |
| 32 | + |
| 33 | + return ResponseEntity.status(403).body(response); |
| 34 | + } |
| 35 | + |
14 | 36 | @ExceptionHandler(Exception.class)
|
15 | 37 | public ResponseEntity<Object> handleException(Exception e) {
|
16 |
| - if (e instanceof BadRequestException) { |
17 |
| - ResponseDTO response = this.responseMapper.toDTO( |
18 |
| - 400, |
19 |
| - e.getMessage(), |
20 |
| - null |
21 |
| - ); |
22 |
| - |
23 |
| - return ResponseEntity.status(400).body(response); |
24 |
| - } |
25 |
| - |
26 |
| - if (e instanceof UnauthorizedException) { |
27 |
| - ResponseDTO response = this.responseMapper.toDTO( |
28 |
| - 403, |
29 |
| - e.getMessage(), |
30 |
| - null |
31 |
| - ); |
32 |
| - |
33 |
| - return ResponseEntity.status(403).body(response); |
34 |
| - } |
35 |
| - |
36 | 38 | ResponseDTO response = this.responseMapper.toDTO(
|
37 | 39 | 500,
|
38 |
| - Arrays.toString(e.getStackTrace()), |
| 40 | +// Arrays.toString(e.getStackTrace()), |
| 41 | + e.getLocalizedMessage(), |
39 | 42 | null
|
40 | 43 | );
|
41 | 44 |
|
|
0 commit comments