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.
47 lines
1.1 KiB
47 lines
1.1 KiB
package models
|
|
|
|
import "fmt"
|
|
|
|
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 BadInputError struct {
|
|
Object string
|
|
Field string
|
|
Problem string
|
|
Min interface{}
|
|
Max interface{}
|
|
}
|
|
|
|
func (e BadInputError) Error() string {
|
|
if e.Min != nil && e.Max != nil {
|
|
return fmt.Sprintf("%s.%s: %s (min: %v, max: %v)", e.Object, e.Field, e.Problem, e.Min, e.Max)
|
|
} else if e.Min != nil {
|
|
return fmt.Sprintf("%s.%s: %s (min: %v)", e.Object, e.Field, e.Problem, e.Min)
|
|
} else if e.Max != nil {
|
|
return fmt.Sprintf("%s.%s: %s (max: %v)", e.Object, e.Field, e.Problem, e.Max)
|
|
} else {
|
|
return fmt.Sprintf("%s.%s: %s", e.Object, e.Field, e.Problem)
|
|
}
|
|
}
|
|
|
|
func (e BadInputError) HttpStatus() (int, string, interface{}) {
|
|
return 400, e.Error(), &e
|
|
}
|