mirror of
https://github.com/go-gitea/gitea.git
synced 2024-05-11 05:55:29 +00:00
unified API error response
This commit is contained in:
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user