add:fix CreateWiki

This commit is contained in:
hang 2021-11-16 15:22:12 +08:00
parent 75627d0ceb
commit 44cfd79573
2 changed files with 24 additions and 0 deletions

View File

@ -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 // InternalServerError responds with an error message to the client with the error as a message
// and the file and line of the caller. // and the file and line of the caller.
func (ctx *APIContext) InternalServerError(err error) { func (ctx *APIContext) InternalServerError(err error) {

View File

@ -153,6 +153,7 @@ func CreateWiki(ctx *context.APIContext) {
err := wiki_service.CheckFile(form.Name) err := wiki_service.CheckFile(form.Name)
if err != nil { if err != nil {
ctx.FileNameError()
return return
} }