Handle specific error for GetCodespaceToken
This commit is contained in:
parent
86717f14a1
commit
2a0ea1617b
2 changed files with 13 additions and 2 deletions
|
|
@ -208,6 +208,8 @@ type getCodespaceTokenResponse struct {
|
|||
RepositoryToken string `json:"repository_token"`
|
||||
}
|
||||
|
||||
var ErrNotProvisioned = errors.New("codespace not provisioned")
|
||||
|
||||
func (a *API) GetCodespaceToken(ctx context.Context, ownerLogin, codespaceName string) (string, error) {
|
||||
reqBody, err := json.Marshal(getCodespaceTokenRequest{true})
|
||||
if err != nil {
|
||||
|
|
@ -236,6 +238,11 @@ func (a *API) GetCodespaceToken(ctx context.Context, ownerLogin, codespaceName s
|
|||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
||||
if resp.StatusCode == http.StatusUnprocessableEntity {
|
||||
return "", ErrNotProvisioned
|
||||
}
|
||||
|
||||
return "", jsonErrorResponse(b)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,8 +135,12 @@ func pollForCodespace(ctx context.Context, client apiClient, log logger, duratio
|
|||
log.Print(".")
|
||||
token, err := client.GetCodespaceToken(ctx, user, name)
|
||||
if err != nil {
|
||||
// Do nothing. We expect this to fail until the codespace is provisioned
|
||||
continue
|
||||
if err == api.ErrNotProvisioned {
|
||||
// Do nothing. We expect this to fail until the codespace is provisioned
|
||||
continue
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("failed to get codespace token: %w", err)
|
||||
}
|
||||
|
||||
return client.GetCodespace(ctx, token, user, name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue