go-errhttp/teapot.go

53 lines
900 B
Go
Raw Normal View History

2017-02-06 20:58:13 +00:00
package errhttp
import (
"net/http"
)
var _ Error = internalTeapot{}
var _ ClientError = internalTeapot{}
var _ Teapot = internalTeapot{}
var ClientErrorTeapot ClientError = TeapotWrap(nil).(Teapot)
var ErrHTTPTeapot Error = ClientErrorTeapot
var ErrTeapot error = ClientErrorTeapot
2017-02-06 20:58:13 +00:00
type Teapot interface {
ClientError
Teapot()
}
type internalTeapot struct {
err error
}
func TeapotWrap(err error) error {
return internalTeapot{
err:err,
}
}
func (receiver internalTeapot) 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 (internalTeapot) ErrHTTP() int {
return http.StatusTeapot
}
2017-02-06 20:58:13 +00:00
func (internalTeapot) ClientError() {
// Nothing here.
}
func (internalTeapot) Teapot() {
// Nothing here.
}
func (receiver internalTeapot) Unwrap() error {
return receiver.err
}