forked from Silverfish/proton-bridge
fix(GODT-2390): Add reports for uncaught json and net.opErr
Report to sentry if we see some uncaught network err, but don't force the user logout. If we catch an uncaught json parser error we report the error to sentry and let the user be logged out later. Finally this patch also prints the error type in UserBadEvent sentry report to further help diagnose issues.
This commit is contained in:
committed by
James Houlahan
parent
82c388a0dd
commit
dcf694588c
@ -20,10 +20,11 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"crypto/subtle"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"net"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -647,9 +648,22 @@ func (user *User) doEventPoll(ctx context.Context) error {
|
||||
return fmt.Errorf("failed to handle event due to network issue: %w", err)
|
||||
}
|
||||
|
||||
// If the error is a url.Error, return error to retry later.
|
||||
if urlErr := new(url.Error); errors.As(err, &urlErr) {
|
||||
return fmt.Errorf("failed to handle event due to URL issue: %w", err)
|
||||
// Catch all for uncategorized net errors that may slip through.
|
||||
if netErr := new(net.OpError); errors.As(err, &netErr) {
|
||||
user.eventCh.Enqueue(events.UncategorizedEventError{
|
||||
UserID: user.ID(),
|
||||
Error: err,
|
||||
})
|
||||
|
||||
return fmt.Errorf("failed to handle event due to network issues (uncategorized): %w", err)
|
||||
}
|
||||
|
||||
// In case a json decode error slips through.
|
||||
if jsonErr := new(json.UnmarshalTypeError); errors.As(err, &jsonErr) {
|
||||
user.eventCh.Enqueue(events.UncategorizedEventError{
|
||||
UserID: user.ID(),
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
|
||||
// If the error is a server-side issue, return error to retry later.
|
||||
|
||||
Reference in New Issue
Block a user