|
@@ -8,6 +8,7 @@ import (
|
|
|
|
|
|
"github.com/imgproxy/imgproxy/v3/cookies"
|
|
|
"github.com/imgproxy/imgproxy/v3/errorreport"
|
|
|
+ "github.com/imgproxy/imgproxy/v3/handlers"
|
|
|
"github.com/imgproxy/imgproxy/v3/httpheaders"
|
|
|
"github.com/imgproxy/imgproxy/v3/ierrors"
|
|
|
"github.com/imgproxy/imgproxy/v3/imagedata"
|
|
@@ -45,12 +46,12 @@ func (r *request) acquireProcessingSem(ctx context.Context) (context.CancelFunc,
|
|
|
// but it's an easy way to check if this is an actual timeout
|
|
|
// or the request was canceled
|
|
|
if terr := server.CheckTimeout(ctx); terr != nil {
|
|
|
- return nil, ierrors.Wrap(terr, 0, ierrors.WithCategory(categoryTimeout))
|
|
|
+ return nil, ierrors.Wrap(terr, 0, ierrors.WithCategory(handlers.CategoryTimeout))
|
|
|
}
|
|
|
|
|
|
// We should never reach this line as err could be only ctx.Err()
|
|
|
// and we've already checked for it. But beter safe than sorry
|
|
|
- return nil, ierrors.Wrap(err, 0, ierrors.WithCategory(categoryQueue))
|
|
|
+ return nil, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategoryQueue))
|
|
|
}
|
|
|
|
|
|
return fn, nil
|
|
@@ -77,7 +78,7 @@ func (r *request) fetchImage(ctx context.Context, do imagedata.DownloadOptions)
|
|
|
if r.config.CookiePassthrough {
|
|
|
do.CookieJar, err = cookies.JarFromRequest(r.imageRequest)
|
|
|
if err != nil {
|
|
|
- return nil, nil, ierrors.Wrap(err, 0, ierrors.WithCategory(categoryDownload))
|
|
|
+ return nil, nil, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategoryDownload))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -98,7 +99,7 @@ func (r *request) handleDownloadError(
|
|
|
}
|
|
|
|
|
|
// Just send error
|
|
|
- monitoring.SendError(ctx, categoryDownload, err)
|
|
|
+ monitoring.SendError(ctx, handlers.CategoryDownload, err)
|
|
|
|
|
|
// We didn't return, so we have to report error
|
|
|
if err.ShouldReport() {
|
|
@@ -173,7 +174,7 @@ func (r *request) writeDebugHeaders(result *processing.Result, originData imaged
|
|
|
// Try to read origin image size
|
|
|
size, err := originData.Size()
|
|
|
if err != nil {
|
|
|
- return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryImageDataSize))
|
|
|
+ return ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategoryImageDataSize))
|
|
|
}
|
|
|
|
|
|
r.rw.Header().Set(httpheaders.XOriginContentLength, strconv.Itoa(size))
|
|
@@ -215,7 +216,7 @@ func (r *request) respondWithImage(statusCode int, resultData imagedata.ImageDat
|
|
|
// errors happened.
|
|
|
resultSize, err := resultData.Size()
|
|
|
if err != nil {
|
|
|
- return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryImageDataSize))
|
|
|
+ return ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategoryImageDataSize))
|
|
|
}
|
|
|
|
|
|
r.hwr.SetContentType(resultData.Format().Mime())
|
|
@@ -247,10 +248,10 @@ func (r *request) respondWithImage(statusCode int, resultData imagedata.ImageDat
|
|
|
|
|
|
var ierr *ierrors.Error
|
|
|
if err != nil {
|
|
|
- ierr = newResponseWriteError(err)
|
|
|
+ ierr = handlers.NewResponseWriteError(err)
|
|
|
|
|
|
if r.config.ReportIOErrors {
|
|
|
- return ierrors.Wrap(ierr, 0, ierrors.WithCategory(categoryIO), ierrors.WithShouldReport(true))
|
|
|
+ return ierrors.Wrap(ierr, 0, ierrors.WithCategory(handlers.CategoryIO), ierrors.WithShouldReport(true))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -267,7 +268,7 @@ func (r *request) respondWithImage(statusCode int, resultData imagedata.ImageDat
|
|
|
|
|
|
// wrapDownloadingErr wraps original error to download error
|
|
|
func (r *request) wrapDownloadingErr(originalErr error) *ierrors.Error {
|
|
|
- err := ierrors.Wrap(originalErr, 0, ierrors.WithCategory(categoryDownload))
|
|
|
+ err := ierrors.Wrap(originalErr, 0, ierrors.WithCategory(handlers.CategoryDownload))
|
|
|
|
|
|
// we report this error only if enabled
|
|
|
if r.config.ReportDownloadingErrors {
|