mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09: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