mirror of
https://github.com/volatiletech/authboss.git
synced 2025-07-03 00:47:13 +02:00
More gigantic edits.
- Change response to be more central to Authboss. Make sure it has useful methods and works with the new rendering idioms. - Change the load user methods to all work with context keys, and even be able to set context keys on the current request to avoid setting contexts everywhere in the code base.
This commit is contained in:
41
errors.go
41
errors.go
@ -2,32 +2,6 @@ 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 {
|
||||
@ -38,19 +12,6 @@ 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 {
|
||||
@ -60,5 +21,5 @@ type RenderErr struct {
|
||||
}
|
||||
|
||||
func (r RenderErr) Error() string {
|
||||
return fmt.Sprintf("Error rendering template %q: %v, data: %#v", r.TemplateName, r.Err, r.Data)
|
||||
return fmt.Sprintf("error rendering response %q: %v, data: %#v", r.TemplateName, r.Err, r.Data)
|
||||
}
|
||||
|
Reference in New Issue
Block a user