From bd95447ca5381be8e9594e580129e73dc365e843 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Wed, 8 May 2019 20:51:39 +0600 Subject: [PATCH] Add development errors mode --- config.go | 2 ++ docs/configuration.md | 4 ++++ server.go | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 6a842724..6df8f22b 100644 --- a/config.go +++ b/config.go @@ -169,6 +169,7 @@ type config struct { UserAgent string IgnoreSslVerification bool + DevelopmentErrorsMode bool LocalFileSystemRoot string S3Enabled bool @@ -293,6 +294,7 @@ func init() { strEnvConfig(&conf.UserAgent, "IMGPROXY_USER_AGENT") boolEnvConfig(&conf.IgnoreSslVerification, "IMGPROXY_IGNORE_SSL_VERIFICATION") + boolEnvConfig(&conf.DevelopmentErrorsMode, "IMGPROXY_DEVELOPMENT_ERRORS_MODE") strEnvConfig(&conf.LocalFileSystemRoot, "IMGPROXY_LOCAL_FILESYSTEM_ROOT") diff --git a/docs/configuration.md b/docs/configuration.md index 10f2545f..76475bd1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -61,6 +61,10 @@ When you use imgproxy in a development environment, it can be useful to ignore S * `IMGPROXY_IGNORE_SSL_VERIFICATION`: when true, disables SSL verification, so imgproxy can be used in a development environment with self-signed SSL certificates. +Also you may want imgproxy to respond with the same error message that it writes to the log: + +* `IMGPROXY_DEVELOPMENT_ERRORS_MODE`: when true, imgproxy will respond with detailed error messages. Not recommended for production because some errors may contain stack trace. + ### Compression * `IMGPROXY_QUALITY`: default quality of the resulting image, percentage. Default: `80`; diff --git a/server.go b/server.go index f8dbe00c..6749e816 100644 --- a/server.go +++ b/server.go @@ -175,7 +175,12 @@ func respondWithError(reqID string, rw http.ResponseWriter, err *imgproxyError) logResponse(reqID, err.StatusCode, err.Message) rw.WriteHeader(err.StatusCode) - rw.Write([]byte(err.PublicMessage)) + + if conf.DevelopmentErrorsMode { + rw.Write([]byte(err.Message)) + } else { + rw.Write([]byte(err.PublicMessage)) + } } func respondWithOptions(reqID string, rw http.ResponseWriter) {