mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-09 19:52:30 +02:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package router
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/ierrors"
|
|
)
|
|
|
|
type (
|
|
RouteNotDefinedError string
|
|
RequestCancelledError string
|
|
RequestTimeoutError string
|
|
)
|
|
|
|
func newRouteNotDefinedError(path string) *ierrors.Error {
|
|
return ierrors.Wrap(
|
|
RouteNotDefinedError(fmt.Sprintf("Route for %s is not defined", path)),
|
|
1,
|
|
ierrors.WithStatusCode(http.StatusNotFound),
|
|
ierrors.WithPublicMessage("Not found"),
|
|
ierrors.WithShouldReport(false),
|
|
)
|
|
}
|
|
|
|
func (e RouteNotDefinedError) Error() string { return string(e) }
|
|
|
|
func newRequestCancelledError(after time.Duration) *ierrors.Error {
|
|
return ierrors.Wrap(
|
|
RequestCancelledError(fmt.Sprintf("Request was cancelled after %v", after)),
|
|
1,
|
|
ierrors.WithStatusCode(499),
|
|
ierrors.WithPublicMessage("Cancelled"),
|
|
ierrors.WithShouldReport(false),
|
|
)
|
|
}
|
|
|
|
func (e RequestCancelledError) Error() string { return string(e) }
|
|
|
|
func newRequestTimeoutError(after time.Duration) *ierrors.Error {
|
|
return ierrors.Wrap(
|
|
RequestTimeoutError(fmt.Sprintf("Request was timed out after %v", after)),
|
|
1,
|
|
ierrors.WithStatusCode(http.StatusServiceUnavailable),
|
|
ierrors.WithPublicMessage("Gateway Timeout"),
|
|
ierrors.WithShouldReport(false),
|
|
)
|
|
}
|
|
|
|
func (e RequestTimeoutError) Error() string { return string(e) }
|