From aad5f44f6cb605589fa017bc521e47a4a517b57d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 12 Nov 2020 12:09:41 -0500 Subject: Display server errors on attachment upload --- plugins/base/routes.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/base/routes.go b/plugins/base/routes.go index fa8f35b..df32876 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -737,18 +737,25 @@ func handleComposeNew(ctx *alps.Context) error { func handleComposeAttachment(ctx *alps.Context) error { reader, err := ctx.Request().MultipartReader() if err != nil { - return fmt.Errorf("failed to get multipart form: %v", err) + return ctx.JSON(http.StatusBadRequest, map[string]string{ + "error": "Invalid request", + }) } form, err := reader.ReadForm(32 << 20) // 32 MB if err != nil { - return fmt.Errorf("failed to decode multipart form: %v", err) + return ctx.JSON(http.StatusBadRequest, map[string]string{ + "error": "Invalid request", + }) } var uuids []string for _, fh := range form.File["attachments"] { uuid, err := ctx.Session.PutAttachment(fh, form) if err != nil { - return err + ctx.Logger().Printf("PutAttachment: %v\n", err) + return ctx.JSON(http.StatusBadRequest, map[string]string{ + "error": "failed to store attachment", + }) } uuids = append(uuids, uuid) } -- cgit v1.2.3