Add context for all exceptions

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-21 19:37:20 +08:00
parent 154c929859
commit 986f63c0af
16 changed files with 91 additions and 87 deletions

View File

@@ -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)
}
}