depot/web/fup/fuphttp/errors.go

43 lines
630 B
Go
Raw Normal View History

package fuphttp
import (
"errors"
"fmt"
"gocloud.dev/gcerrors"
)
type fupError struct {
Code gcerrors.ErrorCode
msg string
err error
}
func (e *fupError) Error() string {
var msg string
if e.msg == "" {
msg = fmt.Sprintf("code=%v", e.Code)
} else {
msg = fmt.Sprintf("%s (code=%v)", e.msg, e.Code)
}
if e.err != nil {
msg = fmt.Sprintf("%s: %s", msg, e.err)
}
return msg
}
func (e *fupError) Unwrap() error {
return e.err
}
func errorCode(err error) gcerrors.ErrorCode {
if err == nil {
return gcerrors.OK
}
var e *fupError
if errors.As(err, &e) {
return e.Code
}
return gcerrors.Code(err)
}