aboutsummaryrefslogtreecommitdiff
path: root/routes/api/v1
diff options
context:
space:
mode:
Diffstat (limited to 'routes/api/v1')
-rw-r--r--routes/api/v1/user/app.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/routes/api/v1/user/app.go b/routes/api/v1/user/app.go
index 864ede54..dcc3fca5 100644
--- a/routes/api/v1/user/app.go
+++ b/routes/api/v1/user/app.go
@@ -10,6 +10,7 @@ import (
api "github.com/gogs/go-gogs-client"
"github.com/gogs/gogs/models"
+ "github.com/gogs/gogs/models/errors"
"github.com/gogs/gogs/pkg/context"
)
@@ -33,7 +34,11 @@ func CreateAccessToken(c *context.APIContext, form api.CreateAccessTokenOption)
Name: form.Name,
}
if err := models.NewAccessToken(t); err != nil {
- c.ServerError("NewAccessToken", err)
+ if errors.IsAccessTokenNameAlreadyExist(err) {
+ c.Error(http.StatusUnprocessableEntity, "", err)
+ } else {
+ c.ServerError("NewAccessToken", err)
+ }
return
}
c.JSON(http.StatusCreated, &api.AccessToken{t.Name, t.Sha1})