source: trip-planner/src/main/java/finki/diplomska/tripplanner/models/exceptions/CustomResponseEntityExceptionHandler.java@ 84d0fbb

Last change on this file since 84d0fbb was 1ad8e64, checked in by Ema <ema_spirova@…>, 3 years ago

spring security

  • Property mode set to 100644
File size: 829 bytes
Line 
1package finki.diplomska.tripplanner.models.exceptions;
2
3import org.springframework.http.HttpStatus;
4import org.springframework.http.ResponseEntity;
5import org.springframework.web.bind.annotation.ControllerAdvice;
6import org.springframework.web.bind.annotation.ExceptionHandler;
7import org.springframework.web.bind.annotation.RestController;
8import org.springframework.web.context.request.WebRequest;
9
10@ControllerAdvice
11@RestController
12public class CustomResponseEntityExceptionHandler {
13 @ExceptionHandler
14 public final ResponseEntity<Object> handleUsernameAlreadyExists(UsernameAlreadyExistsException ex, WebRequest request){
15 UsernameAlreadyExistsResponse exceptionResponse = new UsernameAlreadyExistsResponse(ex.getMessage());
16 return new ResponseEntity(exceptionResponse, HttpStatus.BAD_REQUEST);
17 }
18}
Note: See TracBrowser for help on using the repository browser.