invalid_token
The message text is shown in the example below.
| HTTP status | 401 |
type | authentication_error |
| Retry? | No, not unchanged |
| Status | In the public catalog (error-envelope.ts) |
| Extra fields | none |
When it happens
A sign-in token failed verification or is past its lifetime.
Example
{
"error": {
"type": "authentication_error",
"code": "invalid_token",
"message": "The access token is invalid or expired. Run `syntic login` again.",
"param": null,
"request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d"
}
}How to fix it
- Refresh the token once with the refresh token.
- If the refresh fails, start the sign-in flow again.
- Never send a sign-in token where an API key is expected, or the other way round.
Detect it in code
err = resp.json().get("error", {})
if resp.status_code == 401 and err.get("code") == "invalid_token":
log.warning("%s (%s)", err["message"], err["request_id"]) # fix the request; do not retry unchangedRelated
Was this page helpful?