[#648] objsvc/delete: Handle errors in Go style

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-08-25 10:57:31 +03:00 committed by Evgenii Stratonikov
parent d2084ece41
commit f8ba60aa0c
4 changed files with 62 additions and 181 deletions

View file

@ -29,27 +29,17 @@ func (s *Service) Delete(ctx context.Context, prm Prm) error {
exec.setLogger(s.log)
exec.execute(ctx)
return exec.statusError.err
return exec.execute(ctx)
}
func (exec *execCtx) execute(ctx context.Context) {
func (exec *execCtx) execute(ctx context.Context) error {
exec.log.Debug(logs.ServingRequest)
// perform local operation
exec.executeLocal(ctx)
exec.analyzeStatus()
}
func (exec *execCtx) analyzeStatus() {
// analyze local result
switch exec.status {
case statusOK:
exec.log.Debug(logs.OperationFinishedSuccessfully)
default:
exec.log.Debug(logs.OperationFinishedWithError,
zap.String("error", exec.err.Error()),
)
if err := exec.executeLocal(ctx); err != nil {
exec.log.Debug(logs.OperationFinishedWithError, zap.String("error", err.Error()))
return err
}
exec.log.Debug(logs.OperationFinishedSuccessfully)
return nil
}