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

com.envision.core.MarsExceptionControllerAdvice Maven / Gradle / Ivy

package com.envision.core;

import com.envision.exception.MarsValidException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;


/**
 * @author qiweishi
 * @date 2018/11/13
 */
@ControllerAdvice
public class MarsExceptionControllerAdvice {

    @SuppressWarnings("unchecked")
    @ExceptionHandler(AccessDeniedException.class)
    public  ResponseEntity exception(AccessDeniedException exception) {
        //error
        return new ResponseEntity(exception.getMessage(), HttpStatus.UNAUTHORIZED);
    }


    @ExceptionHandler(MarsValidException.class)
    public ResponseEntity handlerMarsValidException(Exception e) {
        //e.getCause() != null ? e.getCause().getMessage() : e.getMessage()
        return new ResponseEntity<>("Valid error,Status code 400.", HttpStatus.BAD_REQUEST);
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public ResponseEntity handlerIllegalArgumentException(Exception e) {
//        e.getCause() != null ? e.getCause().getMessage() : e.getMessage()
        return new ResponseEntity<>("Argument is error,Status code 400", HttpStatus.BAD_REQUEST);
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy