mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 20:22:31 +02:00
* NewDefaultConfig() + LoadFromEnv() * Route order * Changed route switch * categoryConfig * Use Default() in tests
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/ierrors"
|
|
)
|
|
|
|
// Monitoring error categories
|
|
const (
|
|
categoryTimeout = "timeout"
|
|
categoryImageDataSize = "image_data_size"
|
|
categoryPathParsing = "path_parsing"
|
|
categorySecurity = "security"
|
|
categoryQueue = "queue"
|
|
categoryDownload = "download"
|
|
categoryProcessing = "processing"
|
|
categoryIO = "IO"
|
|
categoryConfig = "config(tmp)" // NOTE: THIS IS TEMPORARY
|
|
)
|
|
|
|
type (
|
|
ResponseWriteError struct{ error }
|
|
InvalidURLError string
|
|
TooManyRequestsError struct{}
|
|
)
|
|
|
|
func newResponseWriteError(cause error) *ierrors.Error {
|
|
return ierrors.Wrap(
|
|
ResponseWriteError{cause},
|
|
1,
|
|
ierrors.WithPublicMessage("Failed to write response"),
|
|
)
|
|
}
|
|
|
|
func (e ResponseWriteError) Error() string {
|
|
return fmt.Sprintf("Failed to write response: %s", e.error)
|
|
}
|
|
|
|
func (e ResponseWriteError) Unwrap() error {
|
|
return e.error
|
|
}
|
|
|
|
func newInvalidURLErrorf(status int, format string, args ...interface{}) error {
|
|
return ierrors.Wrap(
|
|
InvalidURLError(fmt.Sprintf(format, args...)),
|
|
1,
|
|
ierrors.WithStatusCode(status),
|
|
ierrors.WithPublicMessage("Invalid URL"),
|
|
ierrors.WithShouldReport(false),
|
|
)
|
|
}
|
|
|
|
func (e InvalidURLError) Error() string { return string(e) }
|
|
|
|
func newTooManyRequestsError() error {
|
|
return ierrors.Wrap(
|
|
TooManyRequestsError{},
|
|
1,
|
|
ierrors.WithStatusCode(http.StatusTooManyRequests),
|
|
ierrors.WithPublicMessage("Too many requests"),
|
|
ierrors.WithShouldReport(false),
|
|
)
|
|
}
|
|
|
|
func (e TooManyRequestsError) Error() string { return "Too many requests" }
|