1 Star 1 Fork 0

wulala乌啦啦/hwpack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
error.go 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
wulala乌啦啦 提交于 2021-08-14 11:16 . 增加语音合成的接口
// Package error is a collection of error-related functionality that aims to
// unify all of the errors across the SDK. Specifically, it abstracts away low
// level errors into higher-level, easier-to-digest errors of two types: SDK
// errors (represented by the `Error` class) and API errors (represented by the
// `APIError` class).
package errors
// Error is a generic error that is returned when something SDK-related
// goes wrong.
type Error struct {
// Code is the specific error code (for debugging purposes)
Code string `json:"code,omitempty"`
// Message is a descriptive message of the error, why it occurred, how to resolve, etc.
Message string `json:"message,omitempty"`
// Info is an optional field describing in detail the error for debugging purposes.
Info string `json:"-"`
}
// Error converts the error to a human-readable, string format.
func (e Error) Error() string {
return e.Message
}
// NewError creates and `Error` object from the given information.
func NewError(code string, message string, info string) *Error {
return &Error{
Code: code,
Message: message,
Info: info,
}
}
// NewFromErrorCode creates an `Error` object based on a predefined code and
// message.
func NewFromErrorCode(code ErrorCode) *Error {
return &Error{
Code: string(code),
Message: errorMessages[code],
}
}
// NewFromErrorCodeInfo creates an `Error` object based on a predefined code
// and also includes some extra information about the error.
func NewFromErrorCodeInfo(code ErrorCode, info string) *Error {
return &Error{
Code: string(code),
Message: errorMessages[code],
Info: info,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wulalade/hwpack.git
git@gitee.com:wulalade/hwpack.git
wulalade
hwpack
hwpack
4a210dae89ef

搜索帮助