ws/internal/http/upgrade/errors.go

36 lines
928 B
Go

package upgrade
import (
"fmt"
)
// 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
}
func (err ErrInvalidOriginPolicy) Error() string {
return fmt.Sprintf("invalid origin policy; (host: '%s' origin: '%s' error: '%s')", err.Host, err.Origin, err.err)
}