distinguish badrequest and conflict / already exists errors

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2020-10-29 14:01:29 +01:00
parent 6382cdae3a
commit cac8f2ef04
2 changed files with 7 additions and 4 deletions

View File

@@ -312,7 +312,7 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
return merrors.InternalServerError(s.id, "could not check if account exists: %v", err.Error())
}
if exists {
return merrors.BadRequest(s.id, "account already exists")
return merrors.Conflict(s.id, "account already exists")
}
if out.PasswordProfile != nil {
@@ -342,7 +342,7 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
indexResults, err := s.index.Add(out)
if err != nil {
s.rollbackCreateAccount(ctx, out)
return merrors.BadRequest(s.id, "Account already exists %v", err.Error())
return merrors.Conflict(s.id, "Account already exists %v", err.Error())
}
s.log.Debug().Interface("account", out).Msg("account after indexing")

View File

@@ -184,9 +184,12 @@ func (o Ocs) AddUser(w http.ResponseWriter, r *http.Request) {
})
if err != nil {
merr := merrors.FromError(err)
if merr.Code == http.StatusBadRequest {
switch merr.Code {
case http.StatusBadRequest:
render.Render(w, r, response.ErrRender(data.MetaBadRequest.StatusCode, merr.Detail))
} else {
case http.StatusConflict:
render.Render(w, r, response.ErrRender(data.MetaInvalidInput.StatusCode, merr.Detail))
default:
render.Render(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
}
o.logger.Error().Err(err).Str("userid", userid).Msg("could not add user")