diff options
author | Unknwon <u@gogs.io> | 2015-10-08 20:36:07 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-10-08 20:36:07 -0400 |
commit | aff49b1c9eaa33f7c530275f2695d6d96699ec5d (patch) | |
tree | c3720601db2e005e57032feb42deac7e347ac713 /modules/middleware/context.go | |
parent | b1941f1da18b8c6ca046771c21f21ba793765518 (diff) | |
download | gitea-aff49b1c9eaa33f7c530275f2695d6d96699ec5d.tar.gz gitea-aff49b1c9eaa33f7c530275f2695d6d96699ec5d.zip |
unified API error response
Diffstat (limited to 'modules/middleware/context.go')
-rw-r--r-- | modules/middleware/context.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 141e8ace40..c08f84925e 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -157,15 +157,22 @@ func (ctx *Context) HandleText(status int, title string) { ctx.RenderData(status, []byte(title)) } -func (ctx *Context) HandleAPI(status int, obj interface{}) { +// APIError logs error with title if status is 500. +func (ctx *Context) APIError(status int, title string, obj interface{}) { var message string if err, ok := obj.(error); ok { message = err.Error() } else { message = obj.(string) } + + if status == 500 { + log.Error(4, "%s: %s", title, message) + } + ctx.JSON(status, map[string]string{ "message": message, + "url": base.DOC_URL, }) } |