Luke Granger-Brown
4c4bd46aa8
We'll need this for cleanup operations as well. This should likely be factored out again into an entirely separate package that deals with storage access.
42 lines
630 B
Go
42 lines
630 B
Go
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)
|
|
}
|