mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
for webapi requests, make canceled contexts a user instead of server error
no need to trigger alerts for user-initiated errors
This commit is contained in:
parent
1be0cf485e
commit
dfddf0e874
3 changed files with 15 additions and 3 deletions
|
@ -78,7 +78,11 @@ func xcheckf(ctx context.Context, err error, format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
errmsg := fmt.Sprintf("%s: %s", msg, err)
|
errmsg := fmt.Sprintf("%s: %s", msg, err)
|
||||||
pkglog.WithContext(ctx).Errorx(msg, err)
|
pkglog.WithContext(ctx).Errorx(msg, err)
|
||||||
panic(&sherpa.Error{Code: "server:error", Message: errmsg})
|
code := "server:error"
|
||||||
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
code = "user:error"
|
||||||
|
}
|
||||||
|
panic(&sherpa.Error{Code: code, Message: errmsg})
|
||||||
}
|
}
|
||||||
|
|
||||||
func xcheckuserf(ctx context.Context, err error, format string, args ...any) {
|
func xcheckuserf(ctx context.Context, err error, format string, args ...any) {
|
||||||
|
|
|
@ -230,7 +230,11 @@ func xcheckf(ctx context.Context, err error, format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
errmsg := fmt.Sprintf("%s: %s", msg, err)
|
errmsg := fmt.Sprintf("%s: %s", msg, err)
|
||||||
pkglog.WithContext(ctx).Errorx(msg, err)
|
pkglog.WithContext(ctx).Errorx(msg, err)
|
||||||
panic(&sherpa.Error{Code: "server:error", Message: errmsg})
|
code := "server:error"
|
||||||
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
code = "user:error"
|
||||||
|
}
|
||||||
|
panic(&sherpa.Error{Code: code, Message: errmsg})
|
||||||
}
|
}
|
||||||
|
|
||||||
func xcheckuserf(ctx context.Context, err error, format string, args ...any) {
|
func xcheckuserf(ctx context.Context, err error, format string, args ...any) {
|
||||||
|
|
|
@ -117,7 +117,11 @@ func xcheckf(ctx context.Context, err error, format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
errmsg := fmt.Sprintf("%s: %s", msg, err)
|
errmsg := fmt.Sprintf("%s: %s", msg, err)
|
||||||
pkglog.WithContext(ctx).Errorx(msg, err)
|
pkglog.WithContext(ctx).Errorx(msg, err)
|
||||||
panic(&sherpa.Error{Code: "server:error", Message: errmsg})
|
code := "server:error"
|
||||||
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
code = "user:error"
|
||||||
|
}
|
||||||
|
panic(&sherpa.Error{Code: code, Message: errmsg})
|
||||||
}
|
}
|
||||||
|
|
||||||
func xcheckuserf(ctx context.Context, err error, format string, args ...any) {
|
func xcheckuserf(ctx context.Context, err error, format string, args ...any) {
|
||||||
|
|
Loading…
Reference in a new issue