forked from forgejo/forgejo
unified API error response
This commit is contained in:
parent
b1941f1da1
commit
aff49b1c9e
13 changed files with 61 additions and 67 deletions
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue