Skip to content

Commit

Permalink
codespace: Handle HTTP request retry interruption (#7846)
Browse files Browse the repository at this point in the history
* codespace: Handle HTTP request retry interruption

* codespace: Make the error message more detailed
  • Loading branch information
azrsh committed Aug 18, 2023
1 parent bded827 commit bb42fa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/codespaces/api/api.go
Expand Up @@ -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))
}
18 changes: 13 additions & 5 deletions internal/codespaces/codespaces.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit bb42fa0

Please sign in to comment.