Skip to content

Commit a596fd9

Browse files
committed
Error handling refactoring
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
1 parent b69bcde commit a596fd9

File tree

11 files changed

+58
-58
lines changed

11 files changed

+58
-58
lines changed

consumers/messages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var (
3636
func Start(ctx context.Context, id string, sub messaging.Subscriber, consumer interface{}, configPath string, logger *slog.Logger) error {
3737
cfg, err := loadConfig(configPath)
3838
if err != nil {
39-
logger.Warn(fmt.Sprintf("Failed to load consumer config: %s", err))
39+
logger.Error(fmt.Sprintf("Failed to load consumer config: %s", err))
4040
}
4141

4242
transformer := makeTransformer(cfg.TransformerCfg, logger)

consumers/notifiers/api/logging.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (lm *loggingMiddleware) CreateSubscription(ctx context.Context, token strin
3838
}
3939
if err != nil {
4040
args = append(args, slog.Any("error", err))
41-
lm.logger.Warn("Create subscription failed to complete successfully", args...)
41+
lm.logger.Error("Create subscription failed to complete successfully", args...)
4242
return
4343
}
4444
lm.logger.Info("Create subscription completed successfully", args...)
@@ -103,7 +103,7 @@ func (lm *loggingMiddleware) RemoveSubscription(ctx context.Context, token, id s
103103
}
104104
if err != nil {
105105
args = append(args, slog.Any("error", err))
106-
lm.logger.Warn("Remove subscription failed to complete successfully", args...)
106+
lm.logger.Error("Remove subscription failed to complete successfully", args...)
107107
return
108108
}
109109
lm.logger.Info("Remove subscription completed successfully", args...)

internal/groups/api/logging.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (lm *loggingMiddleware) CreateGroup(ctx context.Context, token, kind string
3636
}
3737
if err != nil {
3838
args = append(args, slog.Any("error", err))
39-
lm.logger.Warn("Create group failed to complete successfully", args...)
39+
lm.logger.Error("Create group failed to complete successfully", args...)
4040
return
4141
}
4242
lm.logger.Info("Create group completed successfully", args...)
@@ -58,7 +58,7 @@ func (lm *loggingMiddleware) UpdateGroup(ctx context.Context, token string, grou
5858
}
5959
if err != nil {
6060
args = append(args, slog.Any("error", err))
61-
lm.logger.Warn("Update group failed to complete successfully", args...)
61+
lm.logger.Error("Update group failed to complete successfully", args...)
6262
return
6363
}
6464
lm.logger.Info("Update group completed successfully", args...)
@@ -144,7 +144,7 @@ func (lm *loggingMiddleware) EnableGroup(ctx context.Context, token, id string)
144144
}
145145
if err != nil {
146146
args = append(args, slog.Any("error", err))
147-
lm.logger.Warn("Enable group failed to complete successfully", args...)
147+
lm.logger.Error("Enable group failed to complete successfully", args...)
148148
return
149149
}
150150
lm.logger.Info("Enable group completed successfully", args...)
@@ -165,7 +165,7 @@ func (lm *loggingMiddleware) DisableGroup(ctx context.Context, token, id string)
165165
}
166166
if err != nil {
167167
args = append(args, slog.Any("error", err))
168-
lm.logger.Warn("Disable group failed to complete successfully", args...)
168+
lm.logger.Error("Disable group failed to complete successfully", args...)
169169
return
170170
}
171171
lm.logger.Info("Disable group completed successfully", args...)
@@ -204,7 +204,7 @@ func (lm *loggingMiddleware) Assign(ctx context.Context, token, groupID, relatio
204204
}
205205
if err != nil {
206206
args = append(args, slog.Any("error", err))
207-
lm.logger.Warn("Assign member to group failed to complete successfully", args...)
207+
lm.logger.Error("Assign member to group failed to complete successfully", args...)
208208
return
209209
}
210210
lm.logger.Info("Assign member to group completed successfully", args...)
@@ -224,7 +224,7 @@ func (lm *loggingMiddleware) Unassign(ctx context.Context, token, groupID, relat
224224
}
225225
if err != nil {
226226
args = append(args, slog.Any("error", err))
227-
lm.logger.Warn("Unassign member to group failed to complete successfully", args...)
227+
lm.logger.Error("Unassign member to group failed to complete successfully", args...)
228228
return
229229
}
230230
lm.logger.Info("Unassign member to group completed successfully", args...)
@@ -241,7 +241,7 @@ func (lm *loggingMiddleware) DeleteGroup(ctx context.Context, token, id string)
241241
}
242242
if err != nil {
243243
args = append(args, slog.Any("error", err))
244-
lm.logger.Warn("Delete group failed to complete successfully", args...)
244+
lm.logger.Error("Delete group failed to complete successfully", args...)
245245
return
246246
}
247247
lm.logger.Info("Delete group completed successfully", args...)

invitations/middleware/logging.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (lm *logging) SendInvitation(ctx context.Context, token string, invitation
3131
}
3232
if err != nil {
3333
args = append(args, slog.Any("error", err))
34-
lm.logger.Warn("Send invitation failed to complete successfully", args...)
34+
lm.logger.Error("Send invitation failed to complete successfully", args...)
3535
return
3636
}
3737
lm.logger.Info("Send invitation completed successfully", args...)
@@ -84,7 +84,7 @@ func (lm *logging) AcceptInvitation(ctx context.Context, token, domainID string)
8484
}
8585
if err != nil {
8686
args = append(args, slog.Any("error", err))
87-
lm.logger.Warn("Accept invitation failed to complete successfully", args...)
87+
lm.logger.Error("Accept invitation failed to complete successfully", args...)
8888
return
8989
}
9090
lm.logger.Info("Accept invitation completed successfully", args...)
@@ -101,7 +101,7 @@ func (lm *logging) DeleteInvitation(ctx context.Context, token, userID, domainID
101101
}
102102
if err != nil {
103103
args = append(args, slog.Any("error", err))
104-
lm.logger.Warn("Delete invitation failed to complete successfully", args...)
104+
lm.logger.Error("Delete invitation failed to complete successfully", args...)
105105
return
106106
}
107107
lm.logger.Info("Delete invitation completed successfully", args...)

lora/api/logging.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (lm loggingMiddleware) CreateThing(ctx context.Context, thingID, loraDevEUI
3737
}
3838
if err != nil {
3939
args = append(args, slog.Any("error", err))
40-
lm.logger.Warn("Create thing route-map failed to complete successfully", args...)
40+
lm.logger.Error("Create thing route-map failed to complete successfully", args...)
4141
return
4242
}
4343
lm.logger.Info("Create thing route-map completed successfully", args...)
@@ -55,7 +55,7 @@ func (lm loggingMiddleware) UpdateThing(ctx context.Context, thingID, loraDevEUI
5555
}
5656
if err != nil {
5757
args = append(args, slog.Any("error", err))
58-
lm.logger.Warn("Update thing route-map failed to complete successfully", args...)
58+
lm.logger.Error("Update thing route-map failed to complete successfully", args...)
5959
return
6060
}
6161
lm.logger.Info("Update thing route-map completed successfully", args...)
@@ -72,7 +72,7 @@ func (lm loggingMiddleware) RemoveThing(ctx context.Context, thingID string) (er
7272
}
7373
if err != nil {
7474
args = append(args, slog.Any("error", err))
75-
lm.logger.Warn("Remove thing route-map failed to complete successfully", args...)
75+
lm.logger.Error("Remove thing route-map failed to complete successfully", args...)
7676
return
7777
}
7878
lm.logger.Info("Remove thing route-map completed successfully", args...)
@@ -90,7 +90,7 @@ func (lm loggingMiddleware) CreateChannel(ctx context.Context, chanID, loraApp s
9090
}
9191
if err != nil {
9292
args = append(args, slog.Any("error", err))
93-
lm.logger.Warn("Create channel route-map failed to complete successfully", args...)
93+
lm.logger.Error("Create channel route-map failed to complete successfully", args...)
9494
return
9595
}
9696
lm.logger.Info("Create channel route-map completed successfully", args...)
@@ -107,7 +107,7 @@ func (lm loggingMiddleware) UpdateChannel(ctx context.Context, chanID, loraApp s
107107
slog.String("lora_app", loraApp),
108108
}
109109
if err != nil {
110-
lm.logger.Warn("Update channel route-map failed to complete successfully", args...)
110+
lm.logger.Error("Update channel route-map failed to complete successfully", args...)
111111
return
112112
}
113113
lm.logger.Info("Update channel route-map completed successfully", args...)
@@ -123,7 +123,7 @@ func (lm loggingMiddleware) RemoveChannel(ctx context.Context, chanID string) (e
123123
slog.String("channel_id", chanID),
124124
}
125125
if err != nil {
126-
lm.logger.Warn("Remove channel route-map failed to complete successfully", args...)
126+
lm.logger.Error("Remove channel route-map failed to complete successfully", args...)
127127
return
128128
}
129129
lm.logger.Info("Remove channel route-map completed successfully", args...)
@@ -141,7 +141,7 @@ func (lm loggingMiddleware) ConnectThing(ctx context.Context, chanID, thingID st
141141
}
142142
if err != nil {
143143
args := append(args, slog.String("error", err.Error()))
144-
lm.logger.Warn("Connect thing to channel failed to complete successfully", args...)
144+
lm.logger.Error("Connect thing to channel failed to complete successfully", args...)
145145
return
146146
}
147147
lm.logger.Info("Connect thing to channel completed successfully", args...)

opcua/api/logging.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (lm loggingMiddleware) CreateThing(ctx context.Context, mgxThing, opcuaNode
3737
}
3838
if err != nil {
3939
args = append(args, slog.Any("error", err))
40-
lm.logger.Warn("Create thing route-map failed to complete successfully", args...)
40+
lm.logger.Error("Create thing route-map failed to complete successfully", args...)
4141
return
4242
}
4343
lm.logger.Info("Create thing route-map completed successfully", args...)
@@ -55,7 +55,7 @@ func (lm loggingMiddleware) UpdateThing(ctx context.Context, mgxThing, opcuaNode
5555
}
5656
if err != nil {
5757
args = append(args, slog.Any("error", err))
58-
lm.logger.Warn("Update thing route-map failed to complete successfully", args...)
58+
lm.logger.Error("Update thing route-map failed to complete successfully", args...)
5959
return
6060
}
6161
lm.logger.Info("Update thing route-map completed successfully", args...)
@@ -72,7 +72,7 @@ func (lm loggingMiddleware) RemoveThing(ctx context.Context, mgxThing string) (e
7272
}
7373
if err != nil {
7474
args = append(args, slog.Any("error", err))
75-
lm.logger.Warn("Remove thing route-map failed to complete successfully", args...)
75+
lm.logger.Error("Remove thing route-map failed to complete successfully", args...)
7676
return
7777
}
7878
lm.logger.Info("Remove thing route-map completed successfully", args...)
@@ -90,7 +90,7 @@ func (lm loggingMiddleware) CreateChannel(ctx context.Context, mgxChan, opcuaSer
9090
}
9191
if err != nil {
9292
args = append(args, slog.Any("error", err))
93-
lm.logger.Warn("Create channel route-map failed to complete successfully", args...)
93+
lm.logger.Error("Create channel route-map failed to complete successfully", args...)
9494
return
9595
}
9696
lm.logger.Info("Create channel route-map completed successfully", args...)
@@ -108,7 +108,7 @@ func (lm loggingMiddleware) UpdateChannel(ctx context.Context, mgxChanID, opcuaS
108108
}
109109
if err != nil {
110110
args = append(args, slog.Any("error", err))
111-
lm.logger.Warn("Update channel route-map failed to complete successfully", args...)
111+
lm.logger.Error("Update channel route-map failed to complete successfully", args...)
112112
return
113113
}
114114
lm.logger.Info("Update channel route-map completed successfully", args...)
@@ -125,7 +125,7 @@ func (lm loggingMiddleware) RemoveChannel(ctx context.Context, mgxChanID string)
125125
}
126126
if err != nil {
127127
args = append(args, slog.Any("error", err))
128-
lm.logger.Warn("Remove channel route-map failed to complete successfully", args...)
128+
lm.logger.Error("Remove channel route-map failed to complete successfully", args...)
129129
return
130130
}
131131
lm.logger.Info("Remove channel route-map completed successfully", args...)
@@ -143,7 +143,7 @@ func (lm loggingMiddleware) ConnectThing(ctx context.Context, mgxChanID string,
143143
}
144144
if err != nil {
145145
args = append(args, slog.Any("error", err))
146-
lm.logger.Warn("Connect thing to channel failed to complete successfully", args...)
146+
lm.logger.Error("Connect thing to channel failed to complete successfully", args...)
147147
return
148148
}
149149
lm.logger.Info("Connect thing to channel completed successfully", args...)
@@ -161,7 +161,7 @@ func (lm loggingMiddleware) DisconnectThing(ctx context.Context, mgxChanID strin
161161
}
162162
if err != nil {
163163
args = append(args, slog.Any("error", err))
164-
lm.logger.Warn("Disconnect thing from channel failed to complete successfully", args...)
164+
lm.logger.Error("Disconnect thing from channel failed to complete successfully", args...)
165165
return
166166
}
167167
lm.logger.Info("Disconnect thing from channel completed successfully", args...)

provision/api/logging.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (lm *loggingMiddleware) Provision(token, name, externalID, externalKey stri
3333
}
3434
if err != nil {
3535
args = append(args, slog.Any("error", err))
36-
lm.logger.Warn("Provision failed to complete successfully", args...)
36+
lm.logger.Error("Provision failed to complete successfully", args...)
3737
return
3838
}
3939
lm.logger.Info("Provision completed successfully", args...)
@@ -51,7 +51,7 @@ func (lm *loggingMiddleware) Cert(token, thingID, duration string) (cert, key st
5151
}
5252
if err != nil {
5353
args = append(args, slog.Any("error", err))
54-
lm.logger.Warn("Thing certificate failed to create successfully", args...)
54+
lm.logger.Error("Thing certificate failed to create successfully", args...)
5555
return
5656
}
5757
lm.logger.Info("Thing certificate created successfully", args...)
@@ -67,7 +67,7 @@ func (lm *loggingMiddleware) Mapping(token string) (res map[string]interface{},
6767
}
6868
if err != nil {
6969
args = append(args, slog.Any("error", err))
70-
lm.logger.Warn("Mapping failed to complete successfully", args...)
70+
lm.logger.Error("Mapping failed to complete successfully", args...)
7171
return
7272
}
7373
lm.logger.Info("Mapping completed successfully", args...)

things/api/logging.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (lm *loggingMiddleware) CreateThings(ctx context.Context, token string, cli
3232
}
3333
if err != nil {
3434
args = append(args, slog.Any("error", err))
35-
lm.logger.Warn(fmt.Sprintf("Create %d things failed to complete successfully", len(clients)), args...)
35+
lm.logger.Error(fmt.Sprintf("Create %d things failed to complete successfully", len(clients)), args...)
3636
return
3737
}
3838
lm.logger.Info(fmt.Sprintf("Create %d things completed successfully", len(clients)), args...)
@@ -108,7 +108,7 @@ func (lm *loggingMiddleware) UpdateClient(ctx context.Context, token string, cli
108108
}
109109
if err != nil {
110110
args = append(args, slog.Any("error", err))
111-
lm.logger.Warn("Update thing failed to complete successfully", args...)
111+
lm.logger.Error("Update thing failed to complete successfully", args...)
112112
return
113113
}
114114
lm.logger.Info("Update thing completed successfully", args...)
@@ -128,7 +128,7 @@ func (lm *loggingMiddleware) UpdateClientTags(ctx context.Context, token string,
128128
}
129129
if err != nil {
130130
args := append(args, slog.String("error", err.Error()))
131-
lm.logger.Warn("Update thing tags failed to complete successfully", args...)
131+
lm.logger.Error("Update thing tags failed to complete successfully", args...)
132132
return
133133
}
134134
lm.logger.Info("Update thing tags completed successfully", args...)
@@ -147,7 +147,7 @@ func (lm *loggingMiddleware) UpdateClientSecret(ctx context.Context, token, oldS
147147
}
148148
if err != nil {
149149
args = append(args, slog.Any("error", err))
150-
lm.logger.Warn("Update thing secret failed to complete successfully", args...)
150+
lm.logger.Error("Update thing secret failed to complete successfully", args...)
151151
return
152152
}
153153
lm.logger.Info("Update thing secret completed successfully", args...)
@@ -166,7 +166,7 @@ func (lm *loggingMiddleware) EnableClient(ctx context.Context, token, id string)
166166
}
167167
if err != nil {
168168
args = append(args, slog.Any("error", err))
169-
lm.logger.Warn("Enable thing failed to complete successfully", args...)
169+
lm.logger.Error("Enable thing failed to complete successfully", args...)
170170
return
171171
}
172172
lm.logger.Info("Enable thing completed successfully", args...)
@@ -185,7 +185,7 @@ func (lm *loggingMiddleware) DisableClient(ctx context.Context, token, id string
185185
}
186186
if err != nil {
187187
args = append(args, slog.Any("error", err))
188-
lm.logger.Warn("Disable thing failed to complete successfully", args...)
188+
lm.logger.Error("Disable thing failed to complete successfully", args...)
189189
return
190190
}
191191
lm.logger.Info("Disable thing completed successfully", args...)
@@ -222,7 +222,7 @@ func (lm *loggingMiddleware) Identify(ctx context.Context, key string) (id strin
222222
}
223223
if err != nil {
224224
args = append(args, slog.Any("error", err))
225-
lm.logger.Warn("Identify thing failed to complete successfully", args...)
225+
lm.logger.Error("Identify thing failed to complete successfully", args...)
226226
return
227227
}
228228
lm.logger.Info("Identify thing completed successfully", args...)
@@ -241,7 +241,7 @@ func (lm *loggingMiddleware) Authorize(ctx context.Context, req *magistrala.Auth
241241
}
242242
if err != nil {
243243
args = append(args, slog.Any("error", err))
244-
lm.logger.Warn("Authorize failed to complete successfully", args...)
244+
lm.logger.Error("Authorize failed to complete successfully", args...)
245245
return
246246
}
247247
lm.logger.Info("Authorize completed successfully", args...)
@@ -293,7 +293,7 @@ func (lm *loggingMiddleware) DeleteClient(ctx context.Context, token, id string)
293293
}
294294
if err != nil {
295295
args = append(args, slog.Any("error", err))
296-
lm.logger.Warn("Delete thing failed to complete successfully", args...)
296+
lm.logger.Error("Delete thing failed to complete successfully", args...)
297297
return
298298
}
299299
lm.logger.Info("Delete thing completed successfully", args...)

twins/api/logging.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (lm *loggingMiddleware) AddTwin(ctx context.Context, token string, twin twi
3838
}
3939
if err != nil {
4040
args = append(args, slog.Any("error", err))
41-
lm.logger.Warn("Add twin failed to complete successfully", args...)
41+
lm.logger.Error("Add twin failed to complete successfully", args...)
4242
return
4343
}
4444
lm.logger.Info("Add twin completed successfully", args...)
@@ -59,7 +59,7 @@ func (lm *loggingMiddleware) UpdateTwin(ctx context.Context, token string, twin
5959
}
6060
if err != nil {
6161
args = append(args, slog.Any("error", err))
62-
lm.logger.Warn("Update twin failed to complete successfully", args...)
62+
lm.logger.Error("Update twin failed to complete successfully", args...)
6363
return
6464
}
6565
lm.logger.Info("Update twin completed successfully", args...)
@@ -119,7 +119,7 @@ func (lm *loggingMiddleware) SaveStates(ctx context.Context, msg *messaging.Mess
119119
}
120120
if err != nil {
121121
args = append(args, slog.Any("error", err))
122-
lm.logger.Warn("Save states failed to complete successfully", args...)
122+
lm.logger.Error("Save states failed to complete successfully", args...)
123123
return
124124
}
125125
lm.logger.Info("Save states completed successfully", args...)
@@ -158,7 +158,7 @@ func (lm *loggingMiddleware) RemoveTwin(ctx context.Context, token, twinID strin
158158
}
159159
if err != nil {
160160
args = append(args, slog.Any("error", err))
161-
lm.logger.Warn("Remove twin failed to complete successfully", args...)
161+
lm.logger.Error("Remove twin failed to complete successfully", args...)
162162
return
163163
}
164164
lm.logger.Info("Remove twin completed successfully", args...)

0 commit comments

Comments
 (0)