ws/internal/http/upgrade/errors.go

36 lines
928 B
Go
Raw Normal View History

2021-05-14 15:19:02 +00:00
package upgrade
import (
"fmt"
)
2018-09-29 12:39:12 +00:00
// ErrInvalidRequest for invalid requests
// - multiple-value if only 1 expected
type ErrInvalidRequest struct {
Field string
Reason string
}
func (err ErrInvalidRequest) Error() string {
return fmt.Sprintf("invalid field '%s': %s", err.Field, err.Reason)
}
// ErrIncompleteRequest when mandatory request fields are missing (request-line or headers)
// it contains the missing field as a string
type ErrIncompleteRequest string
func (err ErrIncompleteRequest) Error() string {
return fmt.Sprintf("incomplete request, '%s' is invalid or missing", string(err))
}
// ErrInvalidOriginPolicy when a request has a violated origin policy
type ErrInvalidOriginPolicy struct {
Host string
Origin string
err error
}
2018-09-29 12:39:12 +00:00
func (err ErrInvalidOriginPolicy) Error() string {
return fmt.Sprintf("invalid origin policy; (host: '%s' origin: '%s' error: '%s')", err.Host, err.Origin, err.err)
2018-09-29 12:39:12 +00:00
}