1 Star 0 Fork 0

李梦凡/kite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
errors.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
package kite
import (
"errors"
"fmt"
"github.com/koding/kite/dnode"
)
// ErrKeyNotTrusted is returned by verify functions when the key
// should not be trusted.
var ErrKeyNotTrusted = errors.New("kontrol key is not trusted")
// Error is the type of the kite related errors returned from kite package.
type Error struct {
Type string `json:"type"`
Message string `json:"message"`
CodeVal string `json:"code"`
RequestID string `json:"id"`
}
func (e Error) Code() string {
return e.CodeVal
}
func (e Error) Error() string {
s := e.Message
if e.Type != "genericError" && e.Type != "" {
s = e.Type + ": " + e.Message
}
if e.RequestID != "" {
return s + " (" + e.RequestID + ")"
}
return s
}
// createError creates a new kite.Error for the given r variable
func createError(req *Request, r interface{}) *Error {
if r == nil {
return nil
}
var kiteErr *Error
switch err := r.(type) {
case *Error:
kiteErr = err
case *dnode.ArgumentError:
kiteErr = &Error{
Type: "argumentError",
Message: err.Error(),
}
default:
kiteErr = &Error{
Type: "genericError",
Message: fmt.Sprint(r),
}
}
if kiteErr.RequestID == "" && req != nil {
kiteErr.RequestID = req.ID
}
return kiteErr
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vanlemon/kite.git
git@gitee.com:vanlemon/kite.git
vanlemon
kite
kite
master

搜索帮助