Upgrade SysLogInterceptor
This commit is contained in:
@@ -13,8 +13,11 @@ class ResponseResult<T> private constructor(
|
||||
@Schema(description = "数据") val data: T?
|
||||
) : Serializable {
|
||||
companion object {
|
||||
fun <T> build(code: Int, success: Boolean, msg: String, data: T?) =
|
||||
ResponseResult(code, success, msg, data)
|
||||
|
||||
fun <T> build(code: ResponseCode, success: Boolean, msg: String, data: T?) =
|
||||
ResponseResult(code.code, success, msg, data)
|
||||
build(code.code, success, msg, data)
|
||||
|
||||
fun <T> success(code: ResponseCode = ResponseCode.SYSTEM_OK, msg: String = "success", data: T? = null) =
|
||||
build(code, true, msg, data)
|
||||
|
||||
@@ -84,7 +84,7 @@ class ExceptionHandler {
|
||||
|
||||
else -> {
|
||||
logger.error(e.localizedMessage, e)
|
||||
ResponseResult.fail(ResponseCode.SYSTEM_ERROR, data = null)
|
||||
ResponseResult.fail(ResponseCode.SYSTEM_ERROR, e.localizedMessage, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.http.server.ServerHttpResponse
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||
import org.springframework.web.servlet.HandlerInterceptor
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice
|
||||
import top.fatweb.api.entity.common.ResponseCode
|
||||
import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.entity.system.SysLog
|
||||
import top.fatweb.api.service.system.ISysLogService
|
||||
@@ -100,6 +101,11 @@ class SysLogInterceptor(
|
||||
response: ServerHttpResponse
|
||||
): Any? {
|
||||
resultThreadLocal.set(body)
|
||||
|
||||
if (body is ResponseResult<*> && body.code == ResponseCode.SYSTEM_ERROR.code) {
|
||||
return ResponseResult.build(body.code, body.success, "fail", body.data)
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user