添加文件: intelligence_finance_v1_ga/errors.go
This commit is contained in:
parent
a65f2f32af
commit
793aa99471
|
|
@ -0,0 +1,21 @@
|
||||||
|
package intelligence_finance_v1_ga
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// APIError 表示 API 调用返回的错误。
|
||||||
|
type APIError struct {
|
||||||
|
// StatusCode HTTP 状态码。
|
||||||
|
StatusCode int
|
||||||
|
// Code 业务错误码。
|
||||||
|
Code int
|
||||||
|
// Message 错误信息。
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error 实现 error 接口。
|
||||||
|
func (e *APIError) Error() string {
|
||||||
|
if e.Code != 0 {
|
||||||
|
return fmt.Sprintf("api error: code=%d, msg=%s", e.Code, e.Message)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("api error: http status=%d, body=%s", e.StatusCode, e.Message)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue