You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the feature you are requesting, as well as the possible use case(s) for it.
We can have some common functions which can better handle and wrap the other layer errors like (repo, auth, cache layer error) , which can be called service layer and wrapped
Example
// This can be moved to common package and it can be used by other service. funchandleRepoErr(errerror, fallbackErrWrappererror) error {
switch {
caseerrors.Contains(repoerr.ErrNotFound, err):
returnerrors.Wrap(svcerr.ErrNotFound, err)
caseerrors.Contains(repoerr.ErrConflict, err):
returnerrors.Wrap(svcerr.ErrConflict, err)
default:
returnerrors.Wrap(fallbackErrWrapper, err)
}
}
func (svcservice) UpdateClientRole(ctx context.Context, tokenstring, cli mgclients.Client) (mgclients.Client, error) {
tokenUserID, err:=svc.Identify(ctx, token)
iferr!=nil {
return mgclients.Client{}, err
}
iferr:=svc.checkSuperAdmin(ctx, tokenUserID); err!=nil {
return mgclients.Client{}, err
}
client:= mgclients.Client{
ID: cli.ID,
Role: cli.Role,
UpdatedAt: time.Now(),
UpdatedBy: tokenUserID,
}
iferr:=svc.updateClientPolicy(ctx, cli.ID, cli.Role); err!=nil {
return mgclients.Client{}, err
}
client, err=svc.clients.UpdateRole(ctx, client)
iferr!=nil {
// If failed to update role in DB, then revert back to platform admin policy in spicedbiferrRollback:=svc.updateClientPolicy(ctx, cli.ID, mgclients.UserRole); errRollback!=nil {
return mgclients.Client{}, errors.Wrap(errRollback, err)
}
// Here we are calling the repo error handler.return mgclients.Client{}, handleRepoErr(err,svcerr.ErrUpdateEntity)
}
returnclient, nil
}
Indicate the importance of this feature to you.
Must-have
Anything else?
No response
The text was updated successfully, but these errors were encountered:
arvindh123
changed the title
Feature: Handle Repository error in service layer.
Feature: Handle other layers (repo ,cache , auth) error in service layer.
Apr 25, 2024
This works for me. It's a good idea to keep error handling in the "upper" layer anyways (i.e. handle repo error in svc, and svc in API, just like we initially planned).
As for the handleError location, I'd keep it unexported and per-service for the time being. If there is a lot of overlapping, we can consider making it the internal package.
dborovcanin
changed the title
Feature: Handle other layers (repo ,cache , auth) error in service layer.
Feature: Handle other layers (repo ,cache , auth) error in service layer
Apr 30, 2024
Is your feature request related to a problem? Please describe.
Due to #2117 , API doesn't return proper error.
Describe the feature you are requesting, as well as the possible use case(s) for it.
We can have some common functions which can better handle and wrap the other layer errors like (repo, auth, cache layer error) , which can be called service layer and wrapped
Example
Indicate the importance of this feature to you.
Must-have
Anything else?
No response
The text was updated successfully, but these errors were encountered: