2022-05-01 21:11:52 +08:00
|
|
|
// Package curl ...
|
|
|
|
//
|
|
|
|
// Author: go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Description: 定义异常
|
|
|
|
//
|
|
|
|
// File: exception.go
|
|
|
|
//
|
|
|
|
// Version: 1.0.0
|
|
|
|
//
|
|
|
|
// Date: 2022/05/01 20:40:08
|
|
|
|
package curl
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
// Exception 定义异常
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Description: 对于各种异常的描述
|
|
|
|
//
|
|
|
|
// Date: 2022/05/01 20:48:21
|
|
|
|
type Exception struct {
|
|
|
|
Code string `json:"code"` // 异常的标识码
|
|
|
|
Message string `json:"message"` // 异常的描述
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
// BindRouterParamNotFound 绑定到路由的参数不存在
|
|
|
|
BindRouterParamNotFound = "404001"
|
|
|
|
// ResponseCodeNotFound 响应结果获取不到状态码字段
|
|
|
|
ResponseCodeNotFound = "404002"
|
|
|
|
// ResponseMessageNotFound 响应结果获取不到状态码描述字段
|
|
|
|
ResponseMessageNotFound = "404003"
|
|
|
|
// ResponseDataNotFound 响应结果获取不到数据字段
|
|
|
|
ResponseDataNotFound = "404004"
|
|
|
|
// DomainInvalid 域名设置错误, 必须是 http:// 或者 https:// 开头
|
|
|
|
DomainInvalid = "400001"
|
2022-05-02 15:17:21 +08:00
|
|
|
// SendRequestError 请求发送出现异常
|
|
|
|
SendRequestError = "400002"
|
2022-05-01 21:49:17 +08:00
|
|
|
// RequestMethodNotSupport 请求方法不支持
|
|
|
|
RequestMethodNotSupport = "405001"
|
2022-05-01 21:11:52 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// exceptionTable ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Description: 异常信息表
|
|
|
|
//
|
|
|
|
// Date: 2022/05/01 21:02:55
|
|
|
|
var exceptionTable = map[string]string{
|
|
|
|
BindRouterParamNotFound: "绑定到路由的参数{{bind_router_param}}不存在, 请确认参数配置",
|
|
|
|
ResponseCodeNotFound: "基于配置无法获取响应体状态码, 请检查 response_code_field 的配置, 当前配置 {response_code_field}",
|
|
|
|
ResponseMessageNotFound: "基于配置无法获取响应体状态码, 请检查 response_code_message 的配置, 当前配置 {response_code_message}",
|
|
|
|
ResponseDataNotFound: "基于配置无法获取响应体状态码, 请检查 {response_code_data} 的配置, 当前配置 {response_code_data}",
|
|
|
|
DomainInvalid: "api域名配置非法, 必须以 http:// 或者 https:// 开头, 当前配置 {domain}",
|
2022-05-01 21:49:17 +08:00
|
|
|
RequestMethodNotSupport: "当前请求方法 {method} 不支持, 请核对相关配置",
|
2022-05-02 15:17:21 +08:00
|
|
|
SendRequestError: "请求发送出现异常, 异常原因 : {real_reason}",
|
2022-05-01 21:11:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewException 实力化异常
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2022/05/01 21:02:07
|
|
|
|
func NewException(code string, exceptionData map[string]string) *Exception {
|
|
|
|
mes := exceptionTable[code]
|
|
|
|
for k, v := range exceptionData {
|
|
|
|
mes = strings.ReplaceAll(mes, "{"+k+"}", v)
|
|
|
|
}
|
|
|
|
return &Exception{
|
|
|
|
Code: code,
|
|
|
|
Message: mes,
|
|
|
|
}
|
|
|
|
}
|