完善错误处理逻辑,统一使用 BizErr 包装业务错误,提供打印源码跳转并返回合适的 http 状态码
This commit is contained in:
@@ -16,21 +16,19 @@ func Init() {
|
||||
switch env.RunMode {
|
||||
case "debug":
|
||||
handler = tint.NewHandler(writer, &tint.Options{
|
||||
AddSource: true,
|
||||
Level: env.LogLevel,
|
||||
TimeFormat: timeFormat,
|
||||
ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
|
||||
err, ok := attr.Value.Any().(error)
|
||||
if ok {
|
||||
return tint.Err(err)
|
||||
switch v := attr.Value.Any().(type) {
|
||||
case error:
|
||||
return tint.Err(v)
|
||||
}
|
||||
return attr
|
||||
},
|
||||
})
|
||||
case "production":
|
||||
handler = slog.NewJSONHandler(writer, &slog.HandlerOptions{
|
||||
AddSource: false,
|
||||
Level: env.LogLevel,
|
||||
Level: env.LogLevel,
|
||||
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
|
||||
if a.Key == "time" {
|
||||
return slog.String("time", a.Value.Time().Format(timeFormat))
|
||||
|
||||
Reference in New Issue
Block a user