go-errhttp/unauthorized.go

51 lines
874 B
Go
Raw Normal View History

2017-02-06 20:58:13 +00:00
package errhttp
import (
"net/http"
)
var _ Error = internalUnauthorized{}
var _ ClientError = internalUnauthorized{}
var _ Unauthorized = internalUnauthorized{}
var ErrUnauthorized error = UnauthorizedWrap(nil)
2017-02-06 20:58:13 +00:00
type Unauthorized interface {
ClientError
Unauthorized()
}
type internalUnauthorized struct {
err error
}
func UnauthorizedWrap(err error) error {
return internalUnauthorized{
err:err,
}
}
func (receiver internalUnauthorized) Error() string {
2023-10-01 02:30:28 +00:00
err := receiver.err
if nil == err {
return http.StatusText(receiver.ErrHTTP())
}
return err.Error()
2017-02-06 20:58:13 +00:00
}
func (internalUnauthorized) ErrHTTP() int {
return http.StatusUnauthorized
}
2017-02-06 20:58:13 +00:00
func (internalUnauthorized) ClientError() {
// Nothing here.
}
func (internalUnauthorized) Unauthorized() {
// Nothing here.
}
func (receiver internalUnauthorized) Unwrap() error {
return receiver.err
}