一般后台返回数据都是统一的格式,类上code :xxx message:xxxx
像上面这种前端不好取值,所以改造下,返回通用的格式
添加三个异常类
BootOAuth2Exception.java
package com.pwl.blue.auth.exception;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
/**
* @author Pan Weilong
* @date 2019/7/10 10:09
* @description: 接口.
*/
@JsonSerialize(using = BootOAuthExceptionJacksonSerializer.class)
public class BootOAuth2Exception extends OAuth2Exception {
public BootOAuth2Exception(String msg, Throwable t) {
super(msg, t);
}
public BootOAuth2Exception(String msg) {
super(msg);
}
}
BootOAuth2WebResponseExceptionTranslator.java
package com.pwl.blue.auth.exception;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.common.DefaultThrowableAnalyzer;
import o