mirror of
https://github.com/usatiuk/y.git
synced 2025-10-29 02:37:49 +01:00
simple chat creation
This commit is contained in:
@@ -7,6 +7,7 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
@@ -18,28 +19,35 @@ import java.util.Objects;
|
||||
|
||||
@ControllerAdvice
|
||||
public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
@ExceptionHandler(value = {ConstraintViolationException.class})
|
||||
@ExceptionHandler(ConstraintViolationException.class)
|
||||
protected ResponseEntity<Object> handleConstraintViolation(ConstraintViolationException ex, WebRequest request) {
|
||||
return handleExceptionInternal(ex,
|
||||
new ErrorTo(ex.getConstraintViolations().stream().map(ConstraintViolation::getMessage), HttpStatus.BAD_REQUEST.value()),
|
||||
new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = {AuthenticationException.class})
|
||||
@ExceptionHandler(AuthenticationException.class)
|
||||
protected ResponseEntity<Object> handleAuthenticationException(AuthenticationException ex, WebRequest request) {
|
||||
return handleExceptionInternal(ex,
|
||||
new ErrorTo(List.of(ex.getMessage()), HttpStatus.UNAUTHORIZED.value()),
|
||||
new HttpHeaders(), HttpStatus.UNAUTHORIZED, request);
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = {ResponseStatusException.class})
|
||||
@ExceptionHandler(UsernameNotFoundException.class)
|
||||
protected ResponseEntity<Object> handleUsernameNotFoundException(UsernameNotFoundException ex, WebRequest request) {
|
||||
return handleExceptionInternal(ex,
|
||||
new ErrorTo(List.of(ex.getMessage()), HttpStatus.UNAUTHORIZED.value()),
|
||||
new HttpHeaders(), HttpStatus.UNAUTHORIZED, request);
|
||||
}
|
||||
|
||||
@ExceptionHandler(ResponseStatusException.class)
|
||||
protected ResponseEntity<Object> handleResponseStatusException(ResponseStatusException ex, WebRequest request) {
|
||||
return handleExceptionInternal(ex,
|
||||
new ErrorTo(List.of(Objects.requireNonNullElse(ex.getReason(), ex.getStatusCode().toString())), ex.getStatusCode().value()),
|
||||
new HttpHeaders(), ex.getStatusCode(), request);
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = {Exception.class})
|
||||
@ExceptionHandler(Exception.class)
|
||||
protected ResponseEntity<Object> handleGenericException(Exception ex, WebRequest request) {
|
||||
return handleExceptionInternal(ex,
|
||||
new ErrorTo(List.of("Error"), HttpStatus.INTERNAL_SERVER_ERROR.value()),
|
||||
|
||||
Reference in New Issue
Block a user