main
|
Last change
on this file since 700e2f9 was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago |
|
Init
|
-
Property mode
set to
100644
|
|
File size:
959 bytes
|
| Line | |
|---|
| 1 | package com.finki.icare.config;
|
|---|
| 2 |
|
|---|
| 3 | import com.finki.icare.dto.ErrorResponse;
|
|---|
| 4 | import com.finki.icare.exceptions.ICareException;
|
|---|
| 5 | import org.springframework.http.HttpStatus;
|
|---|
| 6 | import org.springframework.http.ResponseEntity;
|
|---|
| 7 | import org.springframework.web.bind.annotation.ExceptionHandler;
|
|---|
| 8 | import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|---|
| 9 |
|
|---|
| 10 | @RestControllerAdvice
|
|---|
| 11 | public class GlobalExceptionHandler {
|
|---|
| 12 |
|
|---|
| 13 | @ExceptionHandler(ICareException.class)
|
|---|
| 14 | public ResponseEntity<ErrorResponse> handleICareException(ICareException e) {
|
|---|
| 15 | return ResponseEntity
|
|---|
| 16 | .status(e.getStatus())
|
|---|
| 17 | .body(new ErrorResponse(e.getMessage()));
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | @ExceptionHandler(Exception.class)
|
|---|
| 21 | public ResponseEntity<ErrorResponse> handleGenericException(Exception e) {
|
|---|
| 22 | return ResponseEntity
|
|---|
| 23 | .status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|---|
| 24 | .body(new ErrorResponse("An internal error occurred"));
|
|---|
| 25 | }
|
|---|
| 26 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.