Loggest thine Stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
2.1 KiB

package models
import "fmt"
func NotFoundIDError(obj string, id int) NotFoundError {
return NotFoundError(fmt.Sprint(obj, " ", id))
}
type NotFoundError string
func (e NotFoundError) Error() string {
return fmt.Sprintf("%s not found or inaccessible", string(e))
}
func (e NotFoundError) HttpStatus() (int, string, interface{}) {
return 404, e.Error(), nil
}
type PermissionDeniedError struct{}
func (e PermissionDeniedError) Error() string {
return "Permission denied"
}
func (e PermissionDeniedError) HttpStatus() (int, string, interface{}) {
return 403, "Permission denied", nil
}
type ForbiddenError string
func (e ForbiddenError) Error() string {
return string(e)
}
func (e ForbiddenError) HttpStatus() (int, string, interface{}) {
return 401, string(e), nil
}
type BadJSONError struct {
Name string
Raw error
}
func (e BadJSONError) Error() string {
return fmt.Sprintf("JSON Error (%s): %s", e.Name, e.Raw)
}
func (e BadJSONError) HttpStatus() (int, string, interface{}) {
return 401, fmt.Sprintf("Invalid JSON for %s", e.Name), e
}
type BadInputError struct {
Object string `json:"object"`
Field string `json:"field,omitempty"`
Problem string `json:"problem"`
Min interface{} `json:"min,omitempty"`
Max interface{} `json:"max,omitempty"`
Element interface{} `json:"element,omitempty"`
}
func (e BadInputError) Error() string {
if e.Min != nil && e.Max != nil {
return fmt.Sprintf("%s (min: %v, max: %v)", e.Problem, e.Min, e.Max)
} else if e.Min != nil {
return fmt.Sprintf("%s (min: %v)", e.Problem, e.Min)
} else if e.Max != nil {
return fmt.Sprintf("%s (max: %v)", e.Problem, e.Max)
} else {
return fmt.Sprintf("%s", e.Problem)
}
}
func (e BadInputError) HttpStatus() (int, string, interface{}) {
return 400, e.Error(), &e
}
type NotImplementedError struct {
Function string `json:"function"`
Message string `json:"message"`
}
func (e NotImplementedError) Error() string {
return fmt.Sprintf("Not implemented in %s: %s", e.Function, e.Message)
}
func (e NotImplementedError) HttpStatus() (int, string, interface{}) {
return 501, e.Error(), nil
}