Return errors in Permissioned API
This commit is contained in:
parent
c0f3bdbb61
commit
4ff83c5744
@ -2,8 +2,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type permKey int
|
type permKey int
|
||||||
@ -50,8 +51,17 @@ func Permissioned(a API) API {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return as error
|
err := xerrors.Errorf("missing permission to invoke '%s' (need '%s')", field.Name, requiredPerm)
|
||||||
panic(fmt.Sprintf("unauthorized call to %s", field.Name))
|
rerr := reflect.ValueOf(&err).Elem()
|
||||||
|
|
||||||
|
if field.Type.NumOut() == 2 {
|
||||||
|
return []reflect.Value{
|
||||||
|
reflect.Zero(field.Type.Out(0)),
|
||||||
|
rerr,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return []reflect.Value{rerr}
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user