diff --git a/modules/context/api.go b/modules/context/api.go index 7fff8e834..faabef44d 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -105,6 +105,29 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) { }) } +func (ctx *APIContext) FileNameError(objs ...interface{}) { + var message = "FileName too long" + var errors []string + + for _, obj := range objs { + // Ignore nil + if obj == nil { + continue + } + + if err, ok := obj.(error); ok { + errors = append(errors, err.Error()) + } else { + message = obj.(string) + } + } + ctx.JSON(500, map[string]interface{}{ + "message": message, + "documentation_url": setting.API.SwaggerURL, + "errors": errors, + }) +} + // InternalServerError responds with an error message to the client with the error as a message // and the file and line of the caller. func (ctx *APIContext) InternalServerError(err error) { diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 43d794769..4ada0b72e 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -153,6 +153,7 @@ func CreateWiki(ctx *context.APIContext) { err := wiki_service.CheckFile(form.Name) if err != nil { + ctx.FileNameError() return }