source: src/main/java/com/example/rezevirajmasa/demo/config/RestExceptionHandler.java@ 5a9c93b

main
Last change on this file since 5a9c93b was 5a9c93b, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Authorization layer

  • Property mode set to 100644
File size: 739 bytes
Line 
1package com.example.rezevirajmasa.demo.config;
2
3import com.example.rezevirajmasa.demo.dto.ErrorDto;
4import com.example.rezevirajmasa.demo.model.exceptions.AppException;
5import org.springframework.http.ResponseEntity;
6import org.springframework.web.bind.annotation.ControllerAdvice;
7import org.springframework.web.bind.annotation.ExceptionHandler;
8import org.springframework.web.bind.annotation.ResponseBody;
9
10@ControllerAdvice
11public class RestExceptionHandler {
12 @ExceptionHandler(value = {AppException.class})
13 @ResponseBody
14 public ResponseEntity<ErrorDto> handleException(AppException ex) {
15 return ResponseEntity.status(ex.getCode())
16 .body(ErrorDto.builder().message(ex.getMessage()).build());
17 }
18}
Note: See TracBrowser for help on using the repository browser.