你能改变401错误响应吗?(Can you change the 401 error response?)
我的问题是,你能改变401错误信息的响应结构吗?
{ "error": "unauthorized", "error_description": "No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken" }例如
{ "timestamp" : 123124354, "status" : 401, "message" : "The username or password are not valid!" }My question is, can you change the structure of the response of the 401 error message?
{ "error": "unauthorized", "error_description": "No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken" }for example
{ "timestamp" : 123124354, "status" : 401, "message" : "The username or password are not valid!" }最满意答案
这是前一段时间的回答: 修改Spring Boot Rest Controller的默认JSON错误响应 。 检查参考指南我建议使用@ControllerAdvice ,以便最灵活地定义如何返回JSON响应。
This was answered a while ago: Modify default JSON error response from Spring Boot Rest Controller. Checking the reference guide I would recommend going with the @ControllerAdvice to give you the most flexibility on defining how the JSON response is returned.
更多推荐
发布评论