|
9 | 9 | import org.springframework.web.bind.annotation.ControllerAdvice;
|
10 | 10 | import org.springframework.web.bind.annotation.ExceptionHandler;
|
11 | 11 |
|
| 12 | +import com.amazonaws.AmazonClientException; |
| 13 | +import com.amazonaws.AmazonServiceException; |
| 14 | +import com.amazonaws.services.s3.model.AmazonS3Exception; |
| 15 | + |
12 | 16 | import jdc.loja.services.exceptions.AuthorizationException;
|
13 | 17 | import jdc.loja.services.exceptions.DataIntegrityException;
|
| 18 | +import jdc.loja.services.exceptions.FileException; |
14 | 19 | import jdc.loja.services.exceptions.ObjectNotFoundException;
|
15 | 20 |
|
16 | 21 | @ControllerAdvice
|
@@ -38,8 +43,33 @@ public ResponseEntity<StandardError> validation(MethodArgumentNotValidException
|
38 | 43 | }
|
39 | 44 |
|
40 | 45 | @ExceptionHandler(AuthorizationException.class)
|
41 |
| - public ResponseEntity<StandardError> objectNotFound(AuthorizationException e, HttpServletRequest req) { |
| 46 | + public ResponseEntity<StandardError> authorization(AuthorizationException e, HttpServletRequest req) { |
42 | 47 | StandardError err = new StandardError(HttpStatus.FORBIDDEN.value(), e.getMessage(), System.currentTimeMillis());
|
43 | 48 | return ResponseEntity.status(HttpStatus.FORBIDDEN).body(err);
|
44 | 49 | }
|
| 50 | + |
| 51 | + @ExceptionHandler(FileException.class) |
| 52 | + public ResponseEntity<StandardError> file(FileException e, HttpServletRequest req) { |
| 53 | + StandardError err = new StandardError(HttpStatus.BAD_REQUEST.value(), e.getMessage(), System.currentTimeMillis()); |
| 54 | + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(err); |
| 55 | + } |
| 56 | + |
| 57 | + @ExceptionHandler(AmazonServiceException.class) |
| 58 | + public ResponseEntity<StandardError> amazonService(AmazonServiceException e, HttpServletRequest req) { |
| 59 | + HttpStatus code = HttpStatus.valueOf(e.getErrorCode()); |
| 60 | + StandardError err = new StandardError(code.value(), e.getMessage(), System.currentTimeMillis()); |
| 61 | + return ResponseEntity.status(code).body(err); |
| 62 | + } |
| 63 | + |
| 64 | + @ExceptionHandler(AmazonClientException.class) |
| 65 | + public ResponseEntity<StandardError> amazonClient(AmazonClientException e, HttpServletRequest req) { |
| 66 | + StandardError err = new StandardError(HttpStatus.BAD_REQUEST.value(), e.getMessage(), System.currentTimeMillis()); |
| 67 | + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(err); |
| 68 | + } |
| 69 | + |
| 70 | + @ExceptionHandler(AmazonS3Exception.class) |
| 71 | + public ResponseEntity<StandardError> amazonS3(AmazonS3Exception e, HttpServletRequest req) { |
| 72 | + StandardError err = new StandardError(HttpStatus.BAD_REQUEST.value(), e.getMessage(), System.currentTimeMillis()); |
| 73 | + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(err); |
| 74 | + } |
45 | 75 | }
|
0 commit comments