Skip to content

Commit 0de6fc0

Browse files
committed
IMGPROXY_REPORT_DOWNLOADING_ERRORS config
1 parent cc5d380 commit 0de6fc0

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
- Reimplemented and more errors-tolerant image size parsing;
66
- TIFF and BMP support;
77
- Using Application Default Credentials when `IMGPROXY_USE_GCS` is set to `true` but `IMGPROXY_GCS_KEY` is not set.
8-
**Note:** If you use `IMGPROXY_GCS_KEY`, it's recommended to set `IMGPROXY_USE_GCS` to `true` since it may be required by future versions to enable GCS support.
8+
**Note:** If you use `IMGPROXY_GCS_KEY`, it's recommended to set `IMGPROXY_USE_GCS` to `true` since it may be required by future versions to enable GCS support;
9+
- Setting `IMGPROXY_REPORT_DOWNLOADING_ERRORS` to `false` disables reporting of downloading errors.
910

1011
## v2.5.0
1112

config.go

+4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ type config struct {
204204
SentryEnvironment string
205205
SentryRelease string
206206

207+
ReportDownloadingErrors bool
208+
207209
FreeMemoryInterval int
208210
DownloadBufferSize int
209211
GZipBufferSize int
@@ -230,6 +232,7 @@ var conf = config{
230232
HoneybadgerEnv: "production",
231233
SentryEnvironment: "production",
232234
SentryRelease: fmt.Sprintf("imgproxy/%s", version),
235+
ReportDownloadingErrors: true,
233236
FreeMemoryInterval: 10,
234237
BufferPoolCalibrationThreshold: 1024,
235238
}
@@ -336,6 +339,7 @@ func configure() {
336339
strEnvConfig(&conf.SentryDSN, "IMGPROXY_SENTRY_DSN")
337340
strEnvConfig(&conf.SentryEnvironment, "IMGPROXY_SENTRY_ENVIRONMENT")
338341
strEnvConfig(&conf.SentryRelease, "IMGPROXY_SENTRY_RELEASE")
342+
boolEnvConfig(&conf.ReportDownloadingErrors, "IMGPROXY_REPORT_DOWNLOADING_ERRORS")
339343

340344
intEnvConfig(&conf.FreeMemoryInterval, "IMGPROXY_FREE_MEMORY_INTERVAL")
341345
intEnvConfig(&conf.DownloadBufferSize, "IMGPROXY_DOWNLOAD_BUFFER_SIZE")

docs/configuration.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,11 @@ imgproxy can report occurred errors to Bugsnag, Honeybadger and Sentry:
187187
* `IMGPROXY_BUGSNAG_KEY`: Bugsnag API key. When provided, enables error reporting to Bugsnag;
188188
* `IMGPROXY_BUGSNAG_STAGE`: Bugsnag stage to report to. Default: `production`;
189189
* `IMGPROXY_HONEYBADGER_KEY`: Honeybadger API key. When provided, enables error reporting to Honeybadger;
190-
* `IMGPROXY_HONEYBADGER_ENV`: Honeybadger env to report to. Default: `production`.
190+
* `IMGPROXY_HONEYBADGER_ENV`: Honeybadger env to report to. Default: `production`;
191191
* `IMGPROXY_SENTRY_DSN`: Sentry project DSN. When provided, enables error reporting to Sentry;
192-
* `IMGPROXY_SENTRY_ENVIRONMENT`: Sentry environment to report to. Default: `production`.
193-
* `IMGPROXY_SENTRY_RELEASE`: Sentry release to report to. Default: `imgproxy/{imgproxy version}`.
192+
* `IMGPROXY_SENTRY_ENVIRONMENT`: Sentry environment to report to. Default: `production`;
193+
* `IMGPROXY_SENTRY_RELEASE`: Sentry release to report to. Default: `imgproxy/{imgproxy version}`;
194+
* `IMGPROXY_REPORT_DOWNLOADING_ERRORS`: when `true`, imgproxy will report downloading errors. Default: `true`.
194195

195196
## Log
196197

download.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,20 @@ func readAndCheckImage(r io.Reader, contentLength int) (*imageData, error) {
151151
func requestImage(imageURL string) (*http.Response, error) {
152152
req, err := http.NewRequest("GET", imageURL, nil)
153153
if err != nil {
154-
return nil, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected()
154+
return nil, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
155155
}
156156

157157
req.Header.Set("User-Agent", conf.UserAgent)
158158

159159
res, err := downloadClient.Do(req)
160160
if err != nil {
161-
return res, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected()
161+
return res, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
162162
}
163163

164164
if res.StatusCode != 200 {
165165
body, _ := ioutil.ReadAll(res.Body)
166166
msg := fmt.Sprintf("Can't download image; Status: %d; %s", res.StatusCode, string(body))
167-
return res, newError(404, msg, msgSourceImageIsUnreachable).MarkAsUnexpected()
167+
return res, newError(404, msg, msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
168168
}
169169

170170
return res, nil

errors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func (e *imgproxyError) StackTrace() []uintptr {
3131
return e.stack
3232
}
3333

34-
func (e *imgproxyError) MarkAsUnexpected() *imgproxyError {
35-
e.Unexpected = true
34+
func (e *imgproxyError) SetUnexpected(u bool) *imgproxyError {
35+
e.Unexpected = u
3636
return e
3737
}
3838

0 commit comments

Comments
 (0)