代码拉取完成,页面将自动刷新
package exception
import (
"fmt"
"net/http"
)
// New(5000, "令牌过期...")
func New(code int, format string, a ...any) *ApiException {
HttpCode := http.StatusInternalServerError
// 0 ~ 5xx
if code/100 < 6 && code/100 > 0 {
HttpCode = code
}
return &ApiException{
BizCode: code,
Message: fmt.Sprintf(format, a...),
// 如果是异常,直接使用http code作为异常, 不做使用200
HttpCode: HttpCode,
}
}
// 业务自定义异常
type ApiException struct {
// 业务异常
BizCode int `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
HttpCode int `json:"http_code"`
}
// 实现Error接口
func (e *ApiException) Error() string {
return e.Message
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。