Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Fix lock POST API to handle the constraint error in the store #229

Merged
merged 3 commits into from
Nov 21, 2021

Conversation

noahingh
Copy link
Member

@noahingh noahingh commented Nov 21, 2021

The lock POST API validates if the environment is already locked or not before locking the environment. To simplify, I've fixed to return an entity_unprocessable error when the store creates a lock.

@noahingh noahingh added the bug Something isn't working label Nov 21, 2021
@noahingh noahingh marked this pull request as ready for review November 21, 2021 00:43
Comment on lines +11 to +22
func (i *Interactor) GetEnv(ctx context.Context, u *ent.User, r *ent.Repo, env string) (*vo.Env, error) {
config, err := i.SCM.GetConfig(ctx, u, r)
if err != nil {
return nil, err
}

if !config.HasEnv(env) {
return nil, e.NewError(e.ErrorCodeConfigUndefinedEnv, nil)
}

return config.GetEnv(env), nil
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add GetEnv

Comment on lines 109 to 113
} else if ent.IsConstraintError(err) {
return nil, e.NewErrorWithMessage(
e.ErrorCodeEntityUnprocessable,
"The lock already exist.",
err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle the constraint error in the store

@noahingh noahingh merged commit 08a0c3e into main Nov 21, 2021
@noahingh noahingh deleted the fix-lock-api branch November 21, 2021 00:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant