tests and cleanup
This commit is contained in:
parent
d0b8dfe340
commit
1d72aff00a
11 changed files with 468 additions and 123 deletions
|
@ -5,53 +5,6 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Parent error `json:"-" schema:"-"`
|
||||
ErrorType errorType `json:"error" schema:"error"`
|
||||
Description string `json:"error_description,omitempty" schema:"error_description,omitempty"`
|
||||
State string `json:"state,omitempty" schema:"state,omitempty"`
|
||||
redirectDisabled bool `schema:"-"`
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
message := "ErrorType=" + string(e.ErrorType)
|
||||
if e.Description != "" {
|
||||
message += " Description=" + e.Description
|
||||
}
|
||||
if e.Parent != nil {
|
||||
message += " Parent=" + e.Parent.Error()
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
func (e *Error) Unwrap() error {
|
||||
return e.Parent
|
||||
}
|
||||
|
||||
func (e *Error) Is(target error) bool {
|
||||
t, ok := target.(*Error)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return e.ErrorType == t.ErrorType &&
|
||||
(e.Description == t.Description || t.Description == "") &&
|
||||
(e.State == t.State || t.State == "")
|
||||
}
|
||||
|
||||
func (e *Error) WithParent(err error) *Error {
|
||||
e.Parent = err
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Error) WithDescription(desc string, args ...interface{}) *Error {
|
||||
e.Description = fmt.Sprintf(desc, args...)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Error) IsRedirectDisabled() bool {
|
||||
return e.redirectDisabled
|
||||
}
|
||||
|
||||
type errorType string
|
||||
|
||||
const (
|
||||
|
@ -126,6 +79,53 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Parent error `json:"-" schema:"-"`
|
||||
ErrorType errorType `json:"error" schema:"error"`
|
||||
Description string `json:"error_description,omitempty" schema:"error_description,omitempty"`
|
||||
State string `json:"state,omitempty" schema:"state,omitempty"`
|
||||
redirectDisabled bool `schema:"-"`
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
message := "ErrorType=" + string(e.ErrorType)
|
||||
if e.Description != "" {
|
||||
message += " Description=" + e.Description
|
||||
}
|
||||
if e.Parent != nil {
|
||||
message += " Parent=" + e.Parent.Error()
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
func (e *Error) Unwrap() error {
|
||||
return e.Parent
|
||||
}
|
||||
|
||||
func (e *Error) Is(target error) bool {
|
||||
t, ok := target.(*Error)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return e.ErrorType == t.ErrorType &&
|
||||
(e.Description == t.Description || t.Description == "") &&
|
||||
(e.State == t.State || t.State == "")
|
||||
}
|
||||
|
||||
func (e *Error) WithParent(err error) *Error {
|
||||
e.Parent = err
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Error) WithDescription(desc string, args ...interface{}) *Error {
|
||||
e.Description = fmt.Sprintf(desc, args...)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Error) IsRedirectDisabled() bool {
|
||||
return e.redirectDisabled
|
||||
}
|
||||
|
||||
// DefaultToServerError checks if the error is an Error
|
||||
// if not the provided error will be wrapped into a ServerError
|
||||
func DefaultToServerError(err error, description string) *Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue