diff --git a/authenticate/authenticate.go b/authenticate/authenticate.go index 8f146ea..3896176 100644 --- a/authenticate/authenticate.go +++ b/authenticate/authenticate.go @@ -99,16 +99,11 @@ func Do(ctx *fasthttp.RequestCtx, path string) (int32, error) { verifiableKeys[utils.DeviceTokenHeader] = string(getParam(utils.DeviceTokenHeader, &ctx.Request)) verifiableKeys, err = auth.verify.Identity(verifiableKeys, path) if err != nil { - switch e := err.(type) { - case veritification.Error: - switch e.Code { - case veritification.ErrorCodeInvalidUserId: - return 0, createError("unauthorized", codes.Unauthenticated, e.Error()) - case veritification.ErrorCodePermittedToCall: - return 0, createError("forbidden", codes.PermissionDenied, e.Error()) - default: - return 0, createError("internal server error", codes.Internal) - } + switch err { + case veritification.ErrorInvalidUserId: + return 0, createError("unauthorized", codes.Unauthenticated, err.Error()) + case veritification.ErrorPermittedToCallUser, veritification.ErrorPermittedToCallApplication: + return 0, createError("forbidden", codes.PermissionDenied, err.Error()) default: return 0, createError("internal server error", codes.Internal) } diff --git a/service/veritification/error.go b/service/veritification/error.go index a913c4e..b5cc9d4 100644 --- a/service/veritification/error.go +++ b/service/veritification/error.go @@ -1,26 +1,9 @@ package veritification -const ( - ErrorCodeInvalidUserId code = 0 - ErrorCodePermittedToCall code = 1 +import "errors" + +var ( + ErrorInvalidUserId = errors.New("received unexpected user identity") + ErrorPermittedToCallApplication = errors.New("application has no rights to call this method") + ErrorPermittedToCallUser = errors.New("user has no rights to call this method") ) - -type ( - code int - - Error struct { - Code code - message string - } -) - -func (e Error) Error() string { - return e.message -} - -func newError(code code, message string) Error { - return Error{ - Code: code, - message: message, - } -} diff --git a/service/veritification/runtime_verify.go b/service/veritification/runtime_verify.go index e31fc3b..f8847a2 100644 --- a/service/veritification/runtime_verify.go +++ b/service/veritification/runtime_verify.go @@ -98,7 +98,7 @@ func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]st return t, err } if msg == permittedToCallInfo { - return t, newError(ErrorCodePermittedToCall, "application has no rights to call this method") + return t, ErrorPermittedToCallApplication } // ===== CHECK USER TOKEN ===== msg, err = v.findStringCmd(resp, 3) @@ -107,7 +107,7 @@ func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]st } userIdentity, found := t[utils.UserIdHeader] if found && msg != userIdentity { - return t, newError(ErrorCodeInvalidUserId, "received unexpected user identity") + return t, ErrorInvalidUserId } // ===== NOT PERMITTED BY USER ID ===== msg, err = v.findStringCmd(resp, 5) @@ -115,7 +115,7 @@ func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]st return t, err } if msg == permittedToCallInfo { - return t, newError(ErrorCodePermittedToCall, "user has no rights to call this method") + return t, ErrorPermittedToCallUser } // ===== CHECK DEVICE TOKEN ===== msg, err = v.findStringCmd(resp, 7)