ICU-738/Refactor internal/db to domain errors (#815)

* Refactor internal/db to domain errors
This commit is contained in:
Louis Ruch authored and GitHub committed 2020-12-21 10:07:34 -08:00
1 parent b5d84495a3
commit bfbb179741
82 files changed
+742 -640

No files matched your search

@@ -173,7 +173,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Account, error
}
u, err := repo.LookupAccount(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("Account %q doesn't exist.", id)
}
return nil, err
@@ -273,7 +273,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
}
rows, err := repo.DeleteAccount(ctx, scopeId, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return false, nil
}
return false, fmt.Errorf("unable to delete account: %w", err)
@@ -309,7 +309,7 @@ func (s Service) changePasswordInRepo(ctx context.Context, scopeId, id string, v
out, err := repo.ChangePassword(ctx, scopeId, id, currentPassword, newPassword, version)
if err != nil {
switch {
case errors.Is(err, errors.ErrRecordNotFound):
case errors.IsNotFoundError(err):
return nil, handlers.NotFoundErrorf("Account not found.")
case errors.Is(err, password.ErrTooShort):
return nil, handlers.InvalidArgumentErrorf("Error in provided request.",
@@ -334,7 +334,7 @@ func (s Service) setPasswordInRepo(ctx context.Context, scopeId, id string, vers
out, err := repo.SetPassword(ctx, scopeId, id, pw, version)
if err != nil {
switch {
case errors.Is(err, errors.ErrRecordNotFound):
case errors.IsNotFoundError(err):
return nil, handlers.NotFoundErrorf("Account not found.")
case errors.Is(err, password.ErrTooShort):
return nil, handlers.InvalidArgumentErrorf("Error in provided request.",
@@ -178,7 +178,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.AuthMethod, er
}
u, err := repo.LookupAuthMethod(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("AuthMethod %q doesn't exist.", id)
}
return nil, err
@@ -287,7 +287,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
}
rows, err := repo.DeleteAuthMethod(ctx, scopeId, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return false, nil
}
return false, fmt.Errorf("unable to delete auth method: %w", err)
@@ -96,7 +96,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.AuthToken, err
}
u, err := repo.LookupAuthToken(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("AuthToken %q doesn't exist.", id)
}
return nil, fmt.Errorf("unable to lookup auth token: %w", err)
@@ -114,7 +114,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
}
rows, err := repo.DeleteAuthToken(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return false, nil
}
return false, fmt.Errorf("unable to delete user: %w", err)
@@ -192,7 +192,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Group, error)
}
g, m, err := repo.LookupGroup(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("Group %q doesn't exist.", id)
}
return nil, fmt.Errorf("unable to get group: %w", err)
@@ -268,7 +268,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
}
rows, err := repo.DeleteGroup(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return false, nil
}
return false, fmt.Errorf("unable to delete group: %w", err)
@@ -244,7 +244,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Role, error) {
}
out, pr, roleGrants, err := repo.LookupRole(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("Role %q doesn't exist.", id)
}
return nil, err
@@ -327,7 +327,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
}
rows, err := repo.DeleteRole(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return false, nil
}
return false, fmt.Errorf("unable to delete role: %w", err)
@@ -99,7 +99,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Session, error
}
sess, _, err := repo.LookupSession(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("Session %q doesn't exist.", id)
}
return nil, err
@@ -278,7 +278,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
}
t, hostSets, err := repo.LookupTarget(ctx, t.GetPublicId())
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("Target %q not found.", t.GetPublicId())
}
return nil, err
@@ -448,7 +448,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Target, error)
}
u, m, err := repo.LookupTarget(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("Target %q doesn't exist.", id)
}
return nil, err
@@ -547,7 +547,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
}
rows, err := repo.DeleteTarget(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return false, nil
}
return false, fmt.Errorf("unable to delete target: %w", err)
@@ -193,7 +193,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.User, error) {
}
u, accts, err := repo.LookupUser(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return nil, handlers.NotFoundErrorf("User %q doesn't exist.", id)
}
return nil, err
@@ -269,7 +269,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
}
rows, err := repo.DeleteUser(ctx, id)
if err != nil {
if errors.Is(err, errors.ErrRecordNotFound) {
if errors.IsNotFoundError(err) {
return false, nil
}
return false, fmt.Errorf("unable to delete user: %w", err)