|
2 | 2 |
|
3 | 3 | import static org.slf4j.LoggerFactory.getLogger; |
4 | 4 |
|
5 | | -import jakarta.servlet.ServletException; |
6 | | -import jakarta.servlet.http.HttpServletRequest; |
7 | | -import jakarta.servlet.http.HttpServletResponse; |
8 | | -import java.io.IOException; |
9 | 5 | import life.qbic.data_download.rest.exceptions.ErrorMessageTranslationService.UserFriendlyErrorMessage; |
10 | 6 | import org.slf4j.Logger; |
11 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 8 | import org.springframework.http.HttpStatus; |
13 | 9 | import org.springframework.http.HttpStatusCode; |
14 | 10 | import org.springframework.http.MediaType; |
15 | 11 | import org.springframework.http.ResponseEntity; |
16 | | -import org.springframework.security.access.AccessDeniedException; |
17 | | -import org.springframework.security.core.Authentication; |
18 | | -import org.springframework.security.core.context.SecurityContextHolder; |
19 | | -import org.springframework.security.web.access.AccessDeniedHandler; |
20 | 12 | import org.springframework.web.bind.annotation.ControllerAdvice; |
21 | 13 | import org.springframework.web.bind.annotation.ExceptionHandler; |
22 | | -import org.springframework.web.bind.annotation.ResponseStatus; |
23 | 14 |
|
24 | 15 | /** |
25 | 16 | * The global exception handler. This exception handler takes effect after authentication and |
@@ -59,6 +50,16 @@ public ResponseEntity<String> unknownException(Exception e) { |
59 | 50 | log.error(e.getMessage(), e); |
60 | 51 | return ResponseEntity |
61 | 52 | .status(HttpStatus.INTERNAL_SERVER_ERROR) |
| 53 | + .contentType(MediaType.TEXT_PLAIN) |
| 54 | + .body("Something went wrong. Please try again later."); |
| 55 | + } |
| 56 | + |
| 57 | + @ExceptionHandler(value = RuntimeException.class) |
| 58 | + public ResponseEntity<String> unknownException(RuntimeException e) { |
| 59 | + log.error(e.getMessage(), e); |
| 60 | + return ResponseEntity |
| 61 | + .status(HttpStatus.INTERNAL_SERVER_ERROR) |
| 62 | + .contentType(MediaType.TEXT_PLAIN) |
62 | 63 | .body("Something went wrong. Please try again later."); |
63 | 64 | } |
64 | 65 |
|
|
0 commit comments