From 560744fb3399b33b8006e5a6a54a473696cc5b34 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 28 May 2020 23:25:54 +0200 Subject: Handle expected errors in AddGPGkey API (#11644) * handle GPG Parse & Email Errors * correct TEST * update Swagger * more Docu --- routers/api/v1/user/gpg_key.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'routers') diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index a4f6d0e924..d5fed96df1 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -144,6 +144,8 @@ func CreateGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption) { // responses: // "201": // "$ref": "#/responses/GPGKey" + // "404": + // "$ref": "#/responses/notFound" // "422": // "$ref": "#/responses/validationError" @@ -169,6 +171,8 @@ func DeleteGPGKey(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "403": // "$ref": "#/responses/forbidden" + // "404": + // "$ref": "#/responses/notFound" if err := models.DeleteGPGKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { if models.IsErrGPGKeyAccessDenied(err) { @@ -186,9 +190,13 @@ func DeleteGPGKey(ctx *context.APIContext) { func HandleAddGPGKeyError(ctx *context.APIContext, err error) { switch { case models.IsErrGPGKeyAccessDenied(err): - ctx.Error(http.StatusUnprocessableEntity, "", "You do not have access to this GPG key") + ctx.Error(http.StatusUnprocessableEntity, "GPGKeyAccessDenied", "You do not have access to this GPG key") case models.IsErrGPGKeyIDAlreadyUsed(err): - ctx.Error(http.StatusUnprocessableEntity, "", "A key with the same id already exists") + ctx.Error(http.StatusUnprocessableEntity, "GPGKeyIDAlreadyUsed", "A key with the same id already exists") + case models.IsErrGPGKeyParsing(err): + ctx.Error(http.StatusUnprocessableEntity, "GPGKeyParsing", err) + case models.IsErrGPGNoEmailFound(err): + ctx.Error(http.StatusNotFound, "GPGNoEmailFound", err) default: ctx.Error(http.StatusInternalServerError, "AddGPGKey", err) } -- cgit v1.2.3