-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
73 lines (58 loc) · 2.35 KB
/
errors.go
File metadata and controls
73 lines (58 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gobookmarks
import "errors"
// ErrRepoNotFound indicates that the bookmarks repository does not exist.
var ErrRepoNotFound = errors.New("repository not found")
// ErrHandled is returned by handlers when they have already written
// a response and no further handlers should run.
var ErrHandled = errors.New("handled")
// ErrSignedOut indicates that the OAuth token is no longer valid and
// the user must authenticate again.
var ErrSignedOut = errors.New("signed out")
// ErrNoProvider indicates that no provider was selected for the request.
var ErrNoProvider = errors.New("no provider selected")
// ErrUserExists indicates that a user already exists when attempting signup.
var ErrUserExists = errors.New("user already exists")
// ErrUserNotFound indicates that a user does not exist when attempting to set a password.
var ErrUserNotFound = errors.New("user not found")
// UserError wraps an error message intended for display to the user.
// It satisfies the error interface so it can be returned like a normal error.
// UserError describes an error that has a user facing message.
// The wrapped error can be inspected using errors.As/Is.
type UserError struct {
Msg string // message shown to the user
Err error // underlying error
}
// Error implements the error interface by returning the underlying error
// message so logs and comparisons use the wrapped error.
func (e UserError) Error() string {
if e.Err == nil {
return e.Msg
}
return e.Err.Error()
}
// Unwrap returns the underlying error.
func (e UserError) Unwrap() error { return e.Err }
// NewUserError creates a UserError with the provided display message and
// underlying cause.
func NewUserError(msg string, err error) error {
return UserError{Msg: msg, Err: err}
}
// SystemError represents a server-side failure that prevents the request
// from completing. The message is shown on a dedicated error page while the
// underlying error is logged for debugging.
type SystemError struct {
Msg string // message shown to the user
Err error // underlying error
}
func (e SystemError) Error() string {
if e.Err == nil {
return e.Msg
}
return e.Err.Error()
}
func (e SystemError) Unwrap() error { return e.Err }
// NewSystemError creates a SystemError with the provided display message and
// underlying cause.
func NewSystemError(msg string, err error) error {
return SystemError{Msg: msg, Err: err}
}