有人可以帮助我自定义SpringBoot 2 OAuth 2.0的Exception响应吗?基本上,我需要将异常响应跟踪到一些特定于应用程序的定制响应中。
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
{
"error": "invalid_token",
"error_description": "Access token expired: sdfhjkudxnkjjkJJHGhgnbHnmbhJGJH"
}
{
"timestamp": "2020-04-29T11:30:47.045+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/testf"
}
类似
{
"status": "error",
"message": "Full authentication is required to access this resource"
}
谢谢...
您可以在配置HttpSecurity时针对403进行此操作:
.exceptionHandling()
.accessDeniedHandler(myCoolAccessDeniedHandler())
类似于documentation中指定的
其他两个可能由您可能定义的某些ExceptionHandler捕获并处理:
public class MyExceptionHandlingController extends ResponseEntityExceptionHandler implements ErrorController