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:
Mechiel Lukkien 2023-12-15 15:47:54 +01:00
parent 1be0cf485e
commit dfddf0e874
No known key found for this signature in database
3 changed files with 15 additions and 3 deletions

View file

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

View file

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

View file

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