source: backend/src/main/java/com/finki/icare/config/GlobalExceptionHandler.java

main
Last change on this file was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago

Init

  • Property mode set to 100644
File size: 959 bytes
Line 
1package com.finki.icare.config;
2
3import com.finki.icare.dto.ErrorResponse;
4import com.finki.icare.exceptions.ICareException;
5import org.springframework.http.HttpStatus;
6import org.springframework.http.ResponseEntity;
7import org.springframework.web.bind.annotation.ExceptionHandler;
8import org.springframework.web.bind.annotation.RestControllerAdvice;
9
10@RestControllerAdvice
11public 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.