AlexxIT/go2rtc · error

nest: wrong status

Error message

nest: wrong status: ${res.Status}

What it means

NewAPI exchanges credentials with the Nest service for an access token and requires HTTP 200. Any non-200 response aborts API construction with the server's status line embedded in the error. This means the token request itself failed (bad credentials, expired refresh token, or service problem).

Solutions

  1. Re-run the Nest OAuth flow to obtain fresh access/refresh tokens and update configuration.
  2. Verify client ID, client secret, and token URL in the API configuration.
  3. Check the Nest service status page for outages, then retry with backoff.
  4. Inspect the response body (via a proxy/log) for the OAuth error code (invalid_grant etc.) to confirm the cause.

Example fix

// before
api, err := nest.NewAPI(ctx, staleRefreshToken)

// after
// re-authenticate to get a new refresh token
refreshToken := runOAuthFlow(clientID, clientSecret)
api, err := nest.NewAPI(ctx, refreshToken)
Defensive patterns

Strategy: try-catch

Validate before calling

// check token/credentials shape before calling NewAPI
if refreshToken == "" {
    return errors.New("missing Nest refresh token; run OAuth flow first")
}

Try / catch

api, err := nest.NewAPI(ctx, refreshToken)
if err != nil {
    if strings.Contains(err.Error(), "wrong status") {
        // token rejected: trigger full re-auth flow
        return triggerReauthentication(err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling nest.NewAPI directly, or indirectly via refreshToken and Dial; the token endpoint returns a status other than 200 (commonly 400/401 for bad or expired tokens).

Common situations: Expired or revoked Nest refresh token; wrong client ID/secret in config; Nest/Google cloud outage; token revoked because the user re-authorized the integration elsewhere.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/c4e3cbf92df33684. Report an issue: GitHub.

Appendix: source

Thrown at pkg/nest/api.go:71

		return api, nil
	}

	data := url.Values{
		"grant_type":    []string{"refresh_token"},
		"client_id":     []string{clientID},
		"client_secret": []string{clientSecret},
		"refresh_token": []string{refreshToken},
	}

	client := &http.Client{Timeout: time.Second * 5000}
	res, err := client.PostForm("https://www.googleapis.com/oauth2/v4/token", data)
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()

	if res.StatusCode != 200 {
		return nil, errors.New("nest: wrong status: " + res.Status)
	}

	var resv struct {
		AccessToken string        `json:"access_token"`
		ExpiresIn   time.Duration `json:"expires_in"`
		Scope       string        `json:"scope"`
		TokenType   string        `json:"token_type"`
	}

	if err = json.NewDecoder(res.Body).Decode(&resv); err != nil {
		return nil, err
	}

	api := &API{
		Token:     resv.AccessToken,
		ExpiresAt: now.Add(resv.ExpiresIn * time.Second),
	}

View on GitHub (pinned to c245815e75)