43.1 Override Spring default white label error - Way 1 - Throw Exception (#3)
This commit is contained in:
@ -2,7 +2,6 @@ package net.shyshkin.study.fullstack.supportportal.backend.exception;
|
|||||||
|
|
||||||
import com.auth0.jwt.exceptions.TokenExpiredException;
|
import com.auth0.jwt.exceptions.TokenExpiredException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.controller.UserResource;
|
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.HttpResponse;
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.HttpResponse;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailExistsException;
|
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailExistsException;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailNotFoundException;
|
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailNotFoundException;
|
||||||
@ -18,6 +17,7 @@ import org.springframework.security.authentication.LockedException;
|
|||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||||
|
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -26,7 +26,7 @@ import java.util.Objects;
|
|||||||
import static org.springframework.http.HttpStatus.*;
|
import static org.springframework.http.HttpStatus.*;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestControllerAdvice(basePackageClasses = {UserResource.class})
|
@RestControllerAdvice
|
||||||
public class ExceptionHandling {
|
public class ExceptionHandling {
|
||||||
private static final String ACCOUNT_LOCKED = "Your account has been locked. Please contact administration";
|
private static final String ACCOUNT_LOCKED = "Your account has been locked. Please contact administration";
|
||||||
private static final String METHOD_IS_NOT_ALLOWED = "This request method is not allowed on this endpoint. Please send a '%s' request";
|
private static final String METHOD_IS_NOT_ALLOWED = "This request method is not allowed on this endpoint. Please send a '%s' request";
|
||||||
@ -75,6 +75,11 @@ public class ExceptionHandling {
|
|||||||
return createHttpResponse(METHOD_NOT_ALLOWED, String.format(METHOD_IS_NOT_ALLOWED, supportedMethod));
|
return createHttpResponse(METHOD_NOT_ALLOWED, String.format(METHOD_IS_NOT_ALLOWED, supportedMethod));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(NoHandlerFoundException.class)
|
||||||
|
public ResponseEntity<HttpResponse> noHandlerFoundException(NoHandlerFoundException exception) {
|
||||||
|
return createHttpResponse(BAD_REQUEST, "This page was not found");
|
||||||
|
}
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public ResponseEntity<HttpResponse> internalServerErrorException(Exception exception) {
|
public ResponseEntity<HttpResponse> internalServerErrorException(Exception exception) {
|
||||||
log.error(exception.getMessage());
|
log.error(exception.getMessage());
|
||||||
|
|||||||
@ -10,6 +10,11 @@ spring:
|
|||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
dialect: org.hibernate.dialect.MySQL8Dialect
|
dialect: org.hibernate.dialect.MySQL8Dialect
|
||||||
|
mvc:
|
||||||
|
throw-exception-if-no-handler-found: true
|
||||||
|
web:
|
||||||
|
resources:
|
||||||
|
add-mappings: false
|
||||||
app:
|
app:
|
||||||
public-urls: /user/login,/user/register,/user/image/**
|
public-urls: /user/login,/user/register,/user/image/**
|
||||||
jwt:
|
jwt:
|
||||||
|
|||||||
Reference in New Issue
Block a user