aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-05-28 23:25:54 +0200
committerGitHub <noreply@github.com>2020-05-28 17:25:54 -0400
commit560744fb3399b33b8006e5a6a54a473696cc5b34 (patch)
tree6cfb6b38c72f711069106591f07dae006cab6aa7 /routers
parent9f5576980411385a21668ce5930e53b89be67a5e (diff)
downloadgitea-560744fb3399b33b8006e5a6a54a473696cc5b34.tar.gz
gitea-560744fb3399b33b8006e5a6a54a473696cc5b34.zip
Handle expected errors in AddGPGkey API (#11644)
* handle GPG Parse & Email Errors * correct TEST * update Swagger * more Docu
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/user/gpg_key.go12
1 files changed, 10 insertions, 2 deletions
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)
}