Files
cms-server/internal/exception/error.go
Asai Neko ebfc21595e
All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Add header for openapi definitions, add span tracer for gin-middlewares
Signed-off-by: Asai Neko <sugar@sne.moe>
2026-03-18 16:18:30 +08:00

20 lines
766 B
Go

package exception
import (
"context"
"log/slog"
)
func ErrorHandler(ctx context.Context, status string, errorCode string, err error) {
switch status {
case StatusSuccess:
slog.InfoContext(ctx, "Service exception!, ErrorCode: "+errorCode, slog.String("error_code", errorCode), slog.Any("error", err))
case StatusUser:
slog.WarnContext(ctx, "Service exception!, ErrorCode: "+errorCode, slog.String("error_code", errorCode), slog.Any("error", err))
case StatusServer:
slog.ErrorContext(ctx, "Service exception!, ErrorCode: "+errorCode, slog.String("error_code", errorCode), slog.Any("error", err))
case StatusClient:
slog.ErrorContext(ctx, "Service exception!, ErrorCode: "+errorCode, slog.String("error_code", errorCode), slog.Any("error", err))
}
}