Add exception handler

This commit is contained in:
2023-10-05 21:10:05 +08:00
parent 6a9ad8d490
commit 78de04713f
7 changed files with 135 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
package top.fatweb.api.entity.common
import io.swagger.v3.oas.annotations.media.Schema
import java.io.Serializable
class ResponseResult<T> private constructor(
@Schema(description = "响应码", defaultValue = "200")
val code: Int,
@Schema(description = "是否调用成功")
val success: Boolean,
@Schema(description = "信息")
val msg: String,
@Schema(description = "数据")
val data: T?
) : Serializable {
companion object {
fun <T> build(code: ResponseCode, success: Boolean, msg: String, data: T?) =
ResponseResult(code.code, success, msg, data)
fun <T> success(code: ResponseCode = ResponseCode.SYSTEM_OK, msg: String = "success", data: T? = null) =
build(code, true, msg, data)
fun <T> fail(code: ResponseCode = ResponseCode.SYSTEM_ERROR, msg: String = "fail", data: T? = null) =
build(code, false, msg, data)
}
}