提交 ef0826ac 作者: Brian Tiger Chow 提交者: Juan Batiz-Benet

fix(commands/err)

I didn't know there were dragons here.

When casting errors we've gotta be careful. Apparently both values and
pointers satisfy the error interface. Type checking for one doesn't
catch the other.

cc @whyrusleeping @mappum @jbenet

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>
上级 ca2828f3
......@@ -103,11 +103,12 @@ func (c *Command) Call(req Request) Response {
if err != nil {
// if returned error is a commands.Error, use its error code
// otherwise, just default the code to ErrNormal
var e Error
e, ok := err.(Error)
if ok {
switch e := err.(type) {
case *Error:
res.SetError(e, e.Code)
} else {
case Error:
res.SetError(e, e.Code)
default:
res.SetError(err, ErrNormal)
}
return res
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论