Browse Source

Add development errors mode

DarthSim 6 years ago
parent
commit
bd95447ca5
3 changed files with 12 additions and 1 deletions
  1. 2 0
      config.go
  2. 4 0
      docs/configuration.md
  3. 6 1
      server.go

+ 2 - 0
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")
 

+ 4 - 0
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`;

+ 6 - 1
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) {