Skip to content

Commit 8467b2c

Browse files
committed
return 500 error msg only if not Production mode
1 parent cd7b120 commit 8467b2c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

modules/context/api.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type APIRedirect struct{}
6969
// If status is 500, also it prints error to log.
7070
func (ctx *APIContext) Error(status int, title string, obj interface{}) {
7171
var message string
72+
7273
if err, ok := obj.(error); ok {
7374
message = err.Error()
7475
} else {
@@ -77,6 +78,10 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
7778

7879
if status == http.StatusInternalServerError {
7980
log.ErrorWithSkip(1, "%s: %s", title, message)
81+
82+
if macaron.Env == macaron.PROD {
83+
message = ""
84+
}
8085
}
8186

8287
ctx.JSON(status, APIError{
@@ -90,8 +95,13 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
9095
func (ctx *APIContext) InternalServerError(err error) {
9196
log.ErrorWithSkip(1, "InternalServerError: %v", err)
9297

98+
var message string
99+
if macaron.Env != macaron.PROD {
100+
message = err.Error()
101+
}
102+
93103
ctx.JSON(http.StatusInternalServerError, APIError{
94-
Message: err.Error(),
104+
Message: message,
95105
URL: setting.API.SwaggerURL,
96106
})
97107
}

0 commit comments

Comments
 (0)