From 8331c43a18c2a96395489d2e685ab843da4ee644 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Mon, 13 May 2019 14:20:31 +0200 Subject: [PATCH] util errors: add ErrUnauthorized --- internal/util/errors.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/util/errors.go b/internal/util/errors.go index 94715a5..945e342 100644 --- a/internal/util/errors.go +++ b/internal/util/errors.go @@ -112,3 +112,22 @@ func IsErrForbidden(err error) bool { _, ok := err.(*ErrForbidden) return ok } + +// ErrUnauthorized represent an error caused by an unauthorized request +// it's used to differentiate an internal error from an user error +type ErrUnauthorized struct { + Err error +} + +func (e *ErrUnauthorized) Error() string { + return e.Err.Error() +} + +func NewErrUnauthorized(err error) *ErrUnauthorized { + return &ErrUnauthorized{Err: err} +} + +func IsErrUnauthorized(err error) bool { + _, ok := err.(*ErrUnauthorized) + return ok +}