diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-03-16 01:22:27 +0800 |
---|---|---|
committer | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-03-16 01:22:27 +0800 |
commit | 9e9ca66467116e9079a2639c00e9e623aca23015 (patch) | |
tree | dacdef5392608ff7107e4dd498959d4899e13e54 /internal/gitutil | |
parent | 82ff0c5852f29daa5f95d965fd50665581e7ea3c (diff) |
refactor: unify error handling in routing layer
Diffstat (limited to 'internal/gitutil')
-rw-r--r-- | internal/gitutil/error.go | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/internal/gitutil/error.go b/internal/gitutil/error.go index d8023f94..20aa3b51 100644 --- a/internal/gitutil/error.go +++ b/internal/gitutil/error.go @@ -6,8 +6,33 @@ package gitutil import ( "github.com/gogs/git-module" + + "gogs.io/gogs/internal/errutil" ) +var _ errutil.NotFound = (*Error)(nil) + +// Error is a wrapper of a Git error, which handles not found. +type Error struct { + error +} + +func (e Error) NotFound() bool { + return IsErrSubmoduleNotExist(e.error) || + IsErrRevisionNotExist(e.error) + +} + +// NewError wraps given error. +func NewError(err error) error { + return Error{error: err} +} + +// IsErrSubmoduleNotExist returns true if the error is git.ErrSubmoduleNotExist. +func IsErrSubmoduleNotExist(err error) bool { + return err == git.ErrSubmoduleNotExist +} + // IsErrRevisionNotExist returns true if the error is git.ErrRevisionNotExist. func IsErrRevisionNotExist(err error) bool { return err == git.ErrRevisionNotExist @@ -17,8 +42,3 @@ func IsErrRevisionNotExist(err error) bool { func IsErrNoMergeBase(err error) bool { return err == git.ErrNoMergeBase } - -// IsErrSubmoduleNotExist returns true if the error is git.ErrSubmoduleNotExist. -func IsErrSubmoduleNotExist(err error) bool { - return err == git.ErrSubmoduleNotExist -} |