Skip to content

Commit

Permalink
feat: add 403 AccessDeniedException handler
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentC35 committed Jan 25, 2024
1 parent c15a73b commit 4f24b55
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.HttpMediaTypeNotSupportedException;
Expand Down Expand Up @@ -363,4 +364,12 @@ public ResponseEntity<ApiError> handleRepositoryEntityNotFoundException(
ApiError error = errorComponent.buildApiErrorObject(request, HttpStatus.NOT_FOUND, ex.getMessage());
return new ResponseEntity<>(error, HttpStatus.NOT_FOUND);
}

@ExceptionHandler({AccessDeniedException.class})
public ResponseEntity<ApiError> handleAccessDeniedException(
AccessDeniedException ex,
WebRequest request) {
ApiError error = errorComponent.buildApiErrorObject(request, HttpStatus.FORBIDDEN, ex.getMessage());
return new ResponseEntity<>(error, HttpStatus.FORBIDDEN);
}
}

0 comments on commit 4f24b55

Please sign in to comment.