WebUI/src/util/http_error.go
Theta-Dev 60034b4815
All checks were successful
continuous-integration/drone/push Build is passing
add server base
2022-02-01 23:08:45 +01:00

39 lines
580 B
Go

package util
import "errors"
type HttpError interface {
error
StatusCode() int
}
type httpErr struct {
err error
statusCode int
}
func HttpErrWrap(e error, statusCode int) HttpError {
return &httpErr{
err: e,
statusCode: statusCode,
}
}
func HttpErrNew(msg string, statusCode int) HttpError {
return HttpErrWrap(errors.New(msg), statusCode)
}
func (e *httpErr) Error() string {
if e.err == nil {
return ""
}
return e.err.Error()
}
func (e *httpErr) Unwrap() error {
return e.err
}
func (e *httpErr) StatusCode() int {
return e.statusCode
}