Add context for all exceptions
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
package exception
|
||||
|
||||
import "log/slog"
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
func ErrorHandler(status string, errorCode string, err error) {
|
||||
func ErrorHandler(ctx context.Context, status string, errorCode string, err error) {
|
||||
switch status {
|
||||
case StatusSuccess:
|
||||
slog.Info("Service exception", "id", errorCode, "err", err)
|
||||
slog.InfoContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
case StatusUser:
|
||||
slog.Warn("Service exception", "id", errorCode, "err", err)
|
||||
slog.WarnContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
case StatusServer:
|
||||
slog.Error("Service exception", "id", errorCode, "err", err)
|
||||
slog.ErrorContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
case StatusClient:
|
||||
slog.Error("Service exception", "id", errorCode, "err", err)
|
||||
slog.ErrorContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user