forked from volatiletech/authboss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
64 lines (53 loc) · 1.65 KB
/
errors.go
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
package authboss
import "fmt"
// AttributeErr represents a failure to retrieve a critical
// piece of data from the storer.
type AttributeErr struct {
Name string
WantKind DataType
GotKind string
}
// NewAttributeErr creates a new attribute err type. Useful for when you want
// to have a type mismatch error.
func NewAttributeErr(name string, kind DataType, val interface{}) AttributeErr {
return AttributeErr{
Name: name,
WantKind: kind,
GotKind: fmt.Sprintf("%T", val),
}
}
func (a AttributeErr) Error() string {
if len(a.GotKind) == 0 {
return fmt.Sprintf("Failed to retrieve database attribute: %s", a.Name)
}
return fmt.Sprintf("Failed to retrieve database attribute, type was wrong: %s (want: %v, got: %s)", a.Name, a.WantKind, a.GotKind)
}
// ClientDataErr represents a failure to retrieve a critical
// piece of client information such as a cookie or session value.
type ClientDataErr struct {
Name string
}
func (c ClientDataErr) Error() string {
return fmt.Sprintf("Failed to retrieve client attribute: %s", c.Name)
}
// ErrAndRedirect represents a general error whose response should
// be to redirect.
type ErrAndRedirect struct {
Err error
Location string
FlashSuccess string
FlashError string
}
func (e ErrAndRedirect) Error() string {
return fmt.Sprintf("Error: %v, Redirecting to: %s", e.Err, e.Location)
}
// RenderErr represents an error that occured during rendering
// of a template.
type RenderErr struct {
TemplateName string
Data interface{}
Err error
}
func (r RenderErr) Error() string {
return fmt.Sprintf("Error rendering template %q: %v, data: %#v", r.TemplateName, r.Err, r.Data)
}