Merge pull request #494 from ericchiang/return-409-if-resource-is-already-created
return 409 status code on duplicate email errors
This commit is contained in:
commit
c0eb36c14b
4 changed files with 21 additions and 3 deletions
|
@ -81,7 +81,7 @@ var (
|
|||
client.ErrorInvalidClientSecret: errorMaker("bad_request", "Secret must be a base64 encoded string", http.StatusBadRequest),
|
||||
|
||||
user.ErrorNotFound: errorMaker("resource_not_found", "Resource could not be found.", http.StatusNotFound),
|
||||
user.ErrorDuplicateEmail: errorMaker("bad_request", "Email already in use.", http.StatusBadRequest),
|
||||
user.ErrorDuplicateEmail: errorMaker("bad_request", "Email already in use.", http.StatusConflict),
|
||||
user.ErrorInvalidEmail: errorMaker("bad_request", "invalid email.", http.StatusBadRequest),
|
||||
|
||||
adminschema.ErrorInvalidRedirectURI: errorMaker("bad_request", "invalid redirectURI.", http.StatusBadRequest),
|
||||
|
|
|
@ -201,7 +201,7 @@ func TestCreateAdmin(t *testing.T) {
|
|||
Email: "Email-1@example.com",
|
||||
Password: "foopass",
|
||||
},
|
||||
errCode: http.StatusBadRequest,
|
||||
errCode: http.StatusConflict,
|
||||
},
|
||||
{
|
||||
// missing Email
|
||||
|
|
|
@ -409,6 +409,24 @@ func TestCreateUser(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
// Duplicate email
|
||||
req: schema.UserCreateRequest{
|
||||
User: &schema.User{
|
||||
Email: "Email-1@example.com",
|
||||
DisplayName: "New User",
|
||||
EmailVerified: true,
|
||||
Admin: false,
|
||||
CreatedAt: clock.Now().Format(time.RFC3339),
|
||||
},
|
||||
RedirectURL: testRedirectURL.String(),
|
||||
},
|
||||
|
||||
token: userGoodToken,
|
||||
|
||||
wantCode: http.StatusConflict,
|
||||
},
|
||||
{
|
||||
|
||||
req: schema.UserCreateRequest{
|
||||
|
|
|
@ -31,7 +31,7 @@ var (
|
|||
|
||||
ErrorInvalidClient = newError("invalid_client", "invalid email.", http.StatusBadRequest)
|
||||
|
||||
ErrorDuplicateEmail = newError("duplicate_email", "Email already in use.", http.StatusBadRequest)
|
||||
ErrorDuplicateEmail = newError("duplicate_email", "Email already in use.", http.StatusConflict)
|
||||
ErrorResourceNotFound = newError("resource_not_found", "Resource could not be found.", http.StatusNotFound)
|
||||
|
||||
ErrorUnauthorized = newError("unauthorized", "Necessary credentials not provided.", http.StatusUnauthorized)
|
||||
|
|
Reference in a new issue