From 62f9ec71f7a65a56876dd55b5398e2a0b61beca6 Mon Sep 17 00:00:00 2001 From: ViktorDolzenko Date: Tue, 17 Feb 2026 14:15:36 +0200 Subject: [PATCH] Viktors Dolzenko task/1-2 global exception --- .../exception/GlobalExceptionHandler.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/lv/ctco/springboottemplate/exception/GlobalExceptionHandler.java diff --git a/src/main/java/lv/ctco/springboottemplate/exception/GlobalExceptionHandler.java b/src/main/java/lv/ctco/springboottemplate/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..ec9cb49 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/exception/GlobalExceptionHandler.java @@ -0,0 +1,16 @@ +package lv.ctco.springboottemplate.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(Exception.class) + public ResponseEntity handleException(Exception ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Oops, something went wrong, try later"); + } +}