diff --git a/api/client.go b/api/client.go index 15015a9669..820e0ff994 100644 --- a/api/client.go +++ b/api/client.go @@ -69,10 +69,6 @@ type ( } ) -func newErrCreateHTTPRequest(err error) error { - return fmt.Errorf("failed to create http request: %w", err) -} - // HTTPStatus returns HTTP status or (-1) for non-HTTP error. func HTTPStatus(err error) int { if err == nil { diff --git a/api/object.go b/api/object.go index 94e1e512a9..c45a51afdd 100644 --- a/api/object.go +++ b/api/object.go @@ -263,7 +263,7 @@ func (args *PutArgs) getBody() (io.ReadCloser, error) { return args.Reader.Open( func (args *PutArgs) put(reqArgs *cmn.HreqArgs) (*http.Request, error) { req, err := reqArgs.Req() if err != nil { - return nil, newErrCreateHTTPRequest(err) + return nil, cmn.NewErrCreateHreq(err) } // Go http doesn't automatically set this for files, so to handle redirect we do it here. req.GetBody = args.getBody @@ -273,7 +273,7 @@ func (args *PutArgs) put(reqArgs *cmn.HreqArgs) (*http.Request, error) { if ckVal == "" { _, ckhash, err := cos.CopyAndChecksum(io.Discard, args.Reader, nil, args.Cksum.Ty()) if err != nil { - return nil, newErrCreateHTTPRequest(err) + return nil, cmn.NewErrCreateHreq(err) } ckVal = hex.EncodeToString(ckhash.Sum()) } @@ -492,7 +492,7 @@ func (args *AppendArgs) getBody() (io.ReadCloser, error) { return args.Reader.Op func (args *AppendArgs) _append(reqArgs *cmn.HreqArgs) (*http.Request, error) { req, err := reqArgs.Req() if err != nil { - return nil, newErrCreateHTTPRequest(err) + return nil, cmn.NewErrCreateHreq(err) } // The HTTP package doesn't automatically set this for files, so it has to be done manually // If it wasn't set, we would need to deal with the redirect manually. diff --git a/cmn/err.go b/cmn/err.go index 5499febb1f..3b2e28911a 100644 --- a/cmn/err.go +++ b/cmn/err.go @@ -241,6 +241,9 @@ type ( ranges []string // RFC 7233 size int64 // [0, size) } + ErrCreateHreq struct { + err error // original + } ) var ( @@ -977,6 +980,18 @@ func IsErrRangeNotSatisfiable(err error) bool { return ok } +// ErrCreateHreq + +func NewErrCreateHreq(err error) *ErrCreateHreq { + return &ErrCreateHreq{err} +} + +func (e *ErrCreateHreq) Error() string { + return fmt.Sprintf("%v (cannot create http request)", e.err) +} + +func (e *ErrCreateHreq) Unwrap() (err error) { return e.err } + // // more is-error helpers //