package com.reyun.saas.security.hadler;

import com.reyun.saas.common.restResult.RestResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;

public class Auth2ResponseExceptionTranslator implements WebResponseExceptionTranslator {
    @Override
    public ResponseEntity<OAuth2Exception> translate(Exception e)  {
        Throwable throwable = e.getCause();
        if (throwable instanceof InvalidTokenException) {
            return new ResponseEntity(new RestResult(-1001,"登录已失效，请重新登陆"), HttpStatus.OK);
        }
        return new ResponseEntity(new RestResult(-10000,"权限错误"), HttpStatus.OK);
    }
}
