Add exception handler
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user