Skip to content

Commit

Permalink
Error handling refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Apr 23, 2024
1 parent e908369 commit 533c151
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion consumers/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
func Start(ctx context.Context, id string, sub messaging.Subscriber, consumer interface{}, configPath string, logger *slog.Logger) error {
cfg, err := loadConfig(configPath)
if err != nil {
logger.Warn(fmt.Sprintf("Failed to load consumer config: %s", err))
logger.Error(fmt.Sprintf("Failed to load consumer config: %s", err))
}

transformer := makeTransformer(cfg.TransformerCfg, logger)
Expand Down
4 changes: 2 additions & 2 deletions consumers/notifiers/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (lm *loggingMiddleware) CreateSubscription(ctx context.Context, token strin
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Create subscription failed to complete successfully", args...)
lm.logger.Error("Create subscription failed to complete successfully", args...)
return
}
lm.logger.Info("Create subscription completed successfully", args...)
Expand Down Expand Up @@ -103,7 +103,7 @@ func (lm *loggingMiddleware) RemoveSubscription(ctx context.Context, token, id s
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove subscription failed to complete successfully", args...)
lm.logger.Error("Remove subscription failed to complete successfully", args...)
return
}
lm.logger.Info("Remove subscription completed successfully", args...)
Expand Down
14 changes: 7 additions & 7 deletions internal/groups/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (lm *loggingMiddleware) CreateGroup(ctx context.Context, token, kind string
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Create group failed to complete successfully", args...)
lm.logger.Error("Create group failed to complete successfully", args...)
return
}
lm.logger.Info("Create group completed successfully", args...)
Expand All @@ -58,7 +58,7 @@ func (lm *loggingMiddleware) UpdateGroup(ctx context.Context, token string, grou
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update group failed to complete successfully", args...)
lm.logger.Error("Update group failed to complete successfully", args...)
return
}
lm.logger.Info("Update group completed successfully", args...)
Expand Down Expand Up @@ -144,7 +144,7 @@ func (lm *loggingMiddleware) EnableGroup(ctx context.Context, token, id string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Enable group failed to complete successfully", args...)
lm.logger.Error("Enable group failed to complete successfully", args...)
return
}
lm.logger.Info("Enable group completed successfully", args...)
Expand All @@ -165,7 +165,7 @@ func (lm *loggingMiddleware) DisableGroup(ctx context.Context, token, id string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Disable group failed to complete successfully", args...)
lm.logger.Error("Disable group failed to complete successfully", args...)
return
}
lm.logger.Info("Disable group completed successfully", args...)
Expand Down Expand Up @@ -204,7 +204,7 @@ func (lm *loggingMiddleware) Assign(ctx context.Context, token, groupID, relatio
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Assign member to group failed to complete successfully", args...)
lm.logger.Error("Assign member to group failed to complete successfully", args...)
return
}
lm.logger.Info("Assign member to group completed successfully", args...)
Expand All @@ -224,7 +224,7 @@ func (lm *loggingMiddleware) Unassign(ctx context.Context, token, groupID, relat
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Unassign member to group failed to complete successfully", args...)
lm.logger.Error("Unassign member to group failed to complete successfully", args...)
return
}
lm.logger.Info("Unassign member to group completed successfully", args...)
Expand All @@ -241,7 +241,7 @@ func (lm *loggingMiddleware) DeleteGroup(ctx context.Context, token, id string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Delete group failed to complete successfully", args...)
lm.logger.Error("Delete group failed to complete successfully", args...)
return
}
lm.logger.Info("Delete group completed successfully", args...)
Expand Down
6 changes: 3 additions & 3 deletions invitations/middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (lm *logging) SendInvitation(ctx context.Context, token string, invitation
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Send invitation failed to complete successfully", args...)
lm.logger.Error("Send invitation failed to complete successfully", args...)
return
}
lm.logger.Info("Send invitation completed successfully", args...)
Expand Down Expand Up @@ -84,7 +84,7 @@ func (lm *logging) AcceptInvitation(ctx context.Context, token, domainID string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Accept invitation failed to complete successfully", args...)
lm.logger.Error("Accept invitation failed to complete successfully", args...)
return
}
lm.logger.Info("Accept invitation completed successfully", args...)
Expand All @@ -101,7 +101,7 @@ func (lm *logging) DeleteInvitation(ctx context.Context, token, userID, domainID
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Delete invitation failed to complete successfully", args...)
lm.logger.Error("Delete invitation failed to complete successfully", args...)
return
}
lm.logger.Info("Delete invitation completed successfully", args...)
Expand Down
14 changes: 7 additions & 7 deletions lora/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (lm loggingMiddleware) CreateThing(ctx context.Context, thingID, loraDevEUI
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Create thing route-map failed to complete successfully", args...)
lm.logger.Error("Create thing route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Create thing route-map completed successfully", args...)
Expand All @@ -55,7 +55,7 @@ func (lm loggingMiddleware) UpdateThing(ctx context.Context, thingID, loraDevEUI
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update thing route-map failed to complete successfully", args...)
lm.logger.Error("Update thing route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Update thing route-map completed successfully", args...)
Expand All @@ -72,7 +72,7 @@ func (lm loggingMiddleware) RemoveThing(ctx context.Context, thingID string) (er
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove thing route-map failed to complete successfully", args...)
lm.logger.Error("Remove thing route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Remove thing route-map completed successfully", args...)
Expand All @@ -90,7 +90,7 @@ func (lm loggingMiddleware) CreateChannel(ctx context.Context, chanID, loraApp s
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Create channel route-map failed to complete successfully", args...)
lm.logger.Error("Create channel route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Create channel route-map completed successfully", args...)
Expand All @@ -107,7 +107,7 @@ func (lm loggingMiddleware) UpdateChannel(ctx context.Context, chanID, loraApp s
slog.String("lora_app", loraApp),
}
if err != nil {
lm.logger.Warn("Update channel route-map failed to complete successfully", args...)
lm.logger.Error("Update channel route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Update channel route-map completed successfully", args...)
Expand All @@ -123,7 +123,7 @@ func (lm loggingMiddleware) RemoveChannel(ctx context.Context, chanID string) (e
slog.String("channel_id", chanID),
}
if err != nil {
lm.logger.Warn("Remove channel route-map failed to complete successfully", args...)
lm.logger.Error("Remove channel route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Remove channel route-map completed successfully", args...)
Expand All @@ -141,7 +141,7 @@ func (lm loggingMiddleware) ConnectThing(ctx context.Context, chanID, thingID st
}
if err != nil {
args := append(args, slog.String("error", err.Error()))
lm.logger.Warn("Connect thing to channel failed to complete successfully", args...)
lm.logger.Error("Connect thing to channel failed to complete successfully", args...)
return
}
lm.logger.Info("Connect thing to channel completed successfully", args...)
Expand Down
16 changes: 8 additions & 8 deletions opcua/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (lm loggingMiddleware) CreateThing(ctx context.Context, mgxThing, opcuaNode
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Create thing route-map failed to complete successfully", args...)
lm.logger.Error("Create thing route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Create thing route-map completed successfully", args...)
Expand All @@ -55,7 +55,7 @@ func (lm loggingMiddleware) UpdateThing(ctx context.Context, mgxThing, opcuaNode
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update thing route-map failed to complete successfully", args...)
lm.logger.Error("Update thing route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Update thing route-map completed successfully", args...)
Expand All @@ -72,7 +72,7 @@ func (lm loggingMiddleware) RemoveThing(ctx context.Context, mgxThing string) (e
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove thing route-map failed to complete successfully", args...)
lm.logger.Error("Remove thing route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Remove thing route-map completed successfully", args...)
Expand All @@ -90,7 +90,7 @@ func (lm loggingMiddleware) CreateChannel(ctx context.Context, mgxChan, opcuaSer
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Create channel route-map failed to complete successfully", args...)
lm.logger.Error("Create channel route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Create channel route-map completed successfully", args...)
Expand All @@ -108,7 +108,7 @@ func (lm loggingMiddleware) UpdateChannel(ctx context.Context, mgxChanID, opcuaS
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update channel route-map failed to complete successfully", args...)
lm.logger.Error("Update channel route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Update channel route-map completed successfully", args...)
Expand All @@ -125,7 +125,7 @@ func (lm loggingMiddleware) RemoveChannel(ctx context.Context, mgxChanID string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove channel route-map failed to complete successfully", args...)
lm.logger.Error("Remove channel route-map failed to complete successfully", args...)
return
}
lm.logger.Info("Remove channel route-map completed successfully", args...)
Expand All @@ -143,7 +143,7 @@ func (lm loggingMiddleware) ConnectThing(ctx context.Context, mgxChanID string,
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Connect thing to channel failed to complete successfully", args...)
lm.logger.Error("Connect thing to channel failed to complete successfully", args...)
return
}
lm.logger.Info("Connect thing to channel completed successfully", args...)
Expand All @@ -161,7 +161,7 @@ func (lm loggingMiddleware) DisconnectThing(ctx context.Context, mgxChanID strin
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Disconnect thing from channel failed to complete successfully", args...)
lm.logger.Error("Disconnect thing from channel failed to complete successfully", args...)
return
}
lm.logger.Info("Disconnect thing from channel completed successfully", args...)
Expand Down
6 changes: 3 additions & 3 deletions provision/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (lm *loggingMiddleware) Provision(token, name, externalID, externalKey stri
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Provision failed to complete successfully", args...)
lm.logger.Error("Provision failed to complete successfully", args...)
return
}
lm.logger.Info("Provision completed successfully", args...)
Expand All @@ -51,7 +51,7 @@ func (lm *loggingMiddleware) Cert(token, thingID, duration string) (cert, key st
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Thing certificate failed to create successfully", args...)
lm.logger.Error("Thing certificate failed to create successfully", args...)
return
}
lm.logger.Info("Thing certificate created successfully", args...)
Expand All @@ -67,7 +67,7 @@ func (lm *loggingMiddleware) Mapping(token string) (res map[string]interface{},
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Mapping failed to complete successfully", args...)
lm.logger.Error("Mapping failed to complete successfully", args...)
return
}
lm.logger.Info("Mapping completed successfully", args...)
Expand Down
18 changes: 9 additions & 9 deletions things/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (lm *loggingMiddleware) CreateThings(ctx context.Context, token string, cli
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn(fmt.Sprintf("Create %d things failed to complete successfully", len(clients)), args...)
lm.logger.Error(fmt.Sprintf("Create %d things failed to complete successfully", len(clients)), args...)
return
}
lm.logger.Info(fmt.Sprintf("Create %d things completed successfully", len(clients)), args...)
Expand Down Expand Up @@ -108,7 +108,7 @@ func (lm *loggingMiddleware) UpdateClient(ctx context.Context, token string, cli
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update thing failed to complete successfully", args...)
lm.logger.Error("Update thing failed to complete successfully", args...)
return
}
lm.logger.Info("Update thing completed successfully", args...)
Expand All @@ -128,7 +128,7 @@ func (lm *loggingMiddleware) UpdateClientTags(ctx context.Context, token string,
}
if err != nil {
args := append(args, slog.String("error", err.Error()))
lm.logger.Warn("Update thing tags failed to complete successfully", args...)
lm.logger.Error("Update thing tags failed to complete successfully", args...)
return
}
lm.logger.Info("Update thing tags completed successfully", args...)
Expand All @@ -147,7 +147,7 @@ func (lm *loggingMiddleware) UpdateClientSecret(ctx context.Context, token, oldS
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update thing secret failed to complete successfully", args...)
lm.logger.Error("Update thing secret failed to complete successfully", args...)
return
}
lm.logger.Info("Update thing secret completed successfully", args...)
Expand All @@ -166,7 +166,7 @@ func (lm *loggingMiddleware) EnableClient(ctx context.Context, token, id string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Enable thing failed to complete successfully", args...)
lm.logger.Error("Enable thing failed to complete successfully", args...)
return
}
lm.logger.Info("Enable thing completed successfully", args...)
Expand All @@ -185,7 +185,7 @@ func (lm *loggingMiddleware) DisableClient(ctx context.Context, token, id string
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Disable thing failed to complete successfully", args...)
lm.logger.Error("Disable thing failed to complete successfully", args...)
return
}
lm.logger.Info("Disable thing completed successfully", args...)
Expand Down Expand Up @@ -222,7 +222,7 @@ func (lm *loggingMiddleware) Identify(ctx context.Context, key string) (id strin
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Identify thing failed to complete successfully", args...)
lm.logger.Error("Identify thing failed to complete successfully", args...)
return
}
lm.logger.Info("Identify thing completed successfully", args...)
Expand All @@ -241,7 +241,7 @@ func (lm *loggingMiddleware) Authorize(ctx context.Context, req *magistrala.Auth
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Authorize failed to complete successfully", args...)
lm.logger.Error("Authorize failed to complete successfully", args...)
return
}
lm.logger.Info("Authorize completed successfully", args...)
Expand Down Expand Up @@ -293,7 +293,7 @@ func (lm *loggingMiddleware) DeleteClient(ctx context.Context, token, id string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Delete thing failed to complete successfully", args...)
lm.logger.Error("Delete thing failed to complete successfully", args...)
return
}
lm.logger.Info("Delete thing completed successfully", args...)
Expand Down
8 changes: 4 additions & 4 deletions twins/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (lm *loggingMiddleware) AddTwin(ctx context.Context, token string, twin twi
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Add twin failed to complete successfully", args...)
lm.logger.Error("Add twin failed to complete successfully", args...)
return
}
lm.logger.Info("Add twin completed successfully", args...)
Expand All @@ -59,7 +59,7 @@ func (lm *loggingMiddleware) UpdateTwin(ctx context.Context, token string, twin
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update twin failed to complete successfully", args...)
lm.logger.Error("Update twin failed to complete successfully", args...)
return
}
lm.logger.Info("Update twin completed successfully", args...)
Expand Down Expand Up @@ -119,7 +119,7 @@ func (lm *loggingMiddleware) SaveStates(ctx context.Context, msg *messaging.Mess
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Save states failed to complete successfully", args...)
lm.logger.Error("Save states failed to complete successfully", args...)
return
}
lm.logger.Info("Save states completed successfully", args...)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (lm *loggingMiddleware) RemoveTwin(ctx context.Context, token, twinID strin
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove twin failed to complete successfully", args...)
lm.logger.Error("Remove twin failed to complete successfully", args...)
return
}
lm.logger.Info("Remove twin completed successfully", args...)
Expand Down
Loading

0 comments on commit 533c151

Please sign in to comment.