优化:服务端捕获 HttpException 仍返回 http 200(报文的code不是200),方便客户端展示错误信息

This commit is contained in:
pppscn 2022-06-07 21:00:30 +08:00
parent 5712c32ff3
commit d2969ef213

View File

@ -15,10 +15,13 @@ class AppExceptionResolver : ExceptionResolver {
override fun onResolve(request: HttpRequest, response: HttpResponse, e: Throwable) {
e.printStackTrace()
if (e is HttpException) {
response.status = e.statusCode
//response.status = e.statusCode
//异常捕获返回 http 200
response.status = StatusCode.SC_OK
} else {
response.status = StatusCode.SC_INTERNAL_SERVER_ERROR
}
//返回统一结构报文
response.setBody(JsonBody(HttpServerUtils.response(e.message.toString())))
}