All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thebund1st.daming.sdk.web.handler.SmsVerificationJwtExceptionHandler Maven / Gradle / Ivy

The newest version!
package com.thebund1st.daming.sdk.web.handler;


import com.thebund1st.daming.sdk.jwt.SmsVerificationJwtException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;

import javax.servlet.http.HttpServletResponse;
import java.security.Principal;

@RestControllerAdvice
public class SmsVerificationJwtExceptionHandler {

    @ExceptionHandler({
            SmsVerificationJwtException.class
    })
    public void handle(SmsVerificationJwtException ex,
                       WebRequest request, HttpServletResponse response) throws Exception {
        Principal userPrincipal = request.getUserPrincipal();
        if (userPrincipal == null) {
            response.sendError(HttpStatus.UNAUTHORIZED.value(), ex.getMessage());
        } else {
            response.sendError(HttpStatus.FORBIDDEN.value(), ex.getMessage());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy