forked from imgproxy/imgproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
67 lines (55 loc) · 1.48 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"net/http"
"github.com/imgproxy/imgproxy/v3/ierrors"
)
type (
ResponseWriteError struct{ error }
InvalidURLError string
TooManyRequestsError struct{}
InvalidSecretError 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" }
func newInvalidSecretError() error {
return ierrors.Wrap(
InvalidSecretError{},
1,
ierrors.WithStatusCode(http.StatusForbidden),
ierrors.WithPublicMessage("Forbidden"),
ierrors.WithShouldReport(false),
)
}
func (e InvalidSecretError) Error() string { return "Invalid secret" }