我正在验证传入的 POST 请求,该请求将在验证请求数据后创建一个数据库实体。我正在尝试在单个请求中收集多个错误,并按照 JSON API 规范作为错误响应进行响应:
https://jsonapi.org/examples/#error-objects-multiple-errors
HTTP/1.1 400 Bad Request
Content-Type: application/vnd.api+json
{
"errors": [
{
"status": "403",
"source": { "pointer": "/data/attributes/secretPowers" },
"detail": "Editing secret powers is not authorized on Sundays."
},
{
"status": "422",
"source": { "pointer": "/data/attributes/volume" },
"detail": "Volume does not, in fact, go to 11."
},
{
"status": "500",
"source": { "pointer": "/data/attributes/reputation" },
"title": "The backend responded with an error",
"detail": "Reputation service not responding after three requests."
}
]
}
是否可以通过@ControllerAdvice
. 当全局异常处理被启用@ControllerAdvice
并抛出异常时,不会捕获下一个异常。