MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / WrapError

Function WrapError

fetcher/errors.go:155–189  ·  view source on GitHub ↗

WrapError wraps generic error into fetcher-specific error types

(err error, skipStack int)

Source from the content-addressed store, hash-verified

153
154// WrapError wraps generic error into fetcher-specific error types
155func WrapError(err error, skipStack int) error {
156 type httpError interface {
157 Timeout() bool
158 }
159
160 var srcErr generichttp.SourceAddressError
161
162 switch {
163 case errors.Is(err, context.DeadlineExceeded):
164 return newRequestTimeoutError(err)
165 case errors.Is(err, context.Canceled):
166 return newRequestCanceledError(err)
167 case errors.Is(err, io.ErrUnexpectedEOF):
168 return PartialResponseError{errctx.NewTextError(
169 "response is incomplete",
170 1,
171 errctx.WithStatusCode(http.StatusUnprocessableEntity),
172 errctx.WithPublicMessage("Source response is incomplete"),
173 errctx.WithShouldReport(false),
174 )}
175 case errors.As(err, &srcErr):
176 return srcErr
177 default:
178 if httpErr, ok := err.(httpError); ok && httpErr.Timeout() {
179 return newRequestTimeoutError(err)
180 }
181
182 //nolint:errorlint // Check for *url.Error itself, not wrapped error
183 if _, ok := err.(*url.Error); ok {
184 return newRequestError(err)
185 }
186 }
187
188 return errctx.WrapWithStackSkip(err, skipStack+1)
189}

Callers 2

wrapDownloadErrorFunction · 0.92
SendMethod · 0.85

Calls 9

NewTextErrorFunction · 0.92
WithStatusCodeFunction · 0.92
WithPublicMessageFunction · 0.92
WithShouldReportFunction · 0.92
WrapWithStackSkipFunction · 0.92
newRequestCanceledErrorFunction · 0.85
newRequestErrorFunction · 0.85
TimeoutMethod · 0.80
newRequestTimeoutErrorFunction · 0.70

Tested by

no test coverage detected