fix(GODT-2341): Handle URL error

This commit is contained in:
James Houlahan 2023-02-07 12:54:01 +01:00 committed by Jakub
parent 2f75131710
commit 4876314cf5
1 changed files with 8 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"io"
"net/url"
"strings"
"sync/atomic"
"time"
@ -617,6 +618,8 @@ func (user *User) startEvents(ctx context.Context) {
}
// doEventPoll is called whenever API events should be polled.
//
//nolint:funlen
func (user *User) doEventPoll(ctx context.Context) error {
user.eventLock.Lock()
defer user.eventLock.Unlock()
@ -644,6 +647,11 @@ 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)
}
// If the error is a server-side issue, return error to retry later.
if apiErr := new(proton.APIError); errors.As(err, &apiErr) && apiErr.Status >= 500 {
return fmt.Errorf("failed to handle event due to server error: %w", err)