codespace: Handle HTTP request retry interruption (#7846)
* codespace: Handle HTTP request retry interruption * codespace: Make the error message more detailed
This commit is contained in:
parent
bded827157
commit
bb42fa07aa
2 changed files with 14 additions and 6 deletions
|
|
@ -1159,6 +1159,6 @@ func (a *API) withRetry(f func() (*http.Response, error)) (*http.Response, error
|
|||
if resp.StatusCode < 500 {
|
||||
return resp, nil
|
||||
}
|
||||
return nil, errors.New("retry")
|
||||
return nil, fmt.Errorf("received response with status code %d", resp.StatusCode)
|
||||
}, backoff.WithMaxRetries(bo, 3))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,14 @@ type logger interface {
|
|||
Printf(f string, v ...interface{})
|
||||
}
|
||||
|
||||
type TimeoutError struct {
|
||||
message string
|
||||
}
|
||||
|
||||
func (e *TimeoutError) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
// ConnectToLiveshare waits for a Codespace to become running,
|
||||
// and connects to it using a Live Share session.
|
||||
func ConnectToLiveshare(ctx context.Context, progress progressIndicator, sessionLogger logger, apiClient apiClient, codespace *api.Codespace) (*liveshare.Session, error) {
|
||||
|
|
@ -63,15 +71,15 @@ func ConnectToLiveshare(ctx context.Context, progress progressIndicator, session
|
|||
return nil
|
||||
}
|
||||
|
||||
return errors.New("codespace not ready yet")
|
||||
return &TimeoutError{message: "codespace not ready yet"}
|
||||
}, backoff.WithContext(expBackoff, ctx))
|
||||
if err != nil {
|
||||
var permErr *backoff.PermanentError
|
||||
if errors.As(err, &permErr) {
|
||||
return nil, err
|
||||
var timeoutErr *TimeoutError
|
||||
if errors.As(err, &timeoutErr) {
|
||||
return nil, errors.New("timed out while waiting for the codespace to start")
|
||||
}
|
||||
|
||||
return nil, errors.New("timed out while waiting for the codespace to start")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue