fix(12): WR-03 validate PAX8 token response shape in Pax8Client.getToken()
This commit is contained in:
parent
76a652ddfd
commit
1bb2b8b0a2
1 changed files with 8 additions and 1 deletions
|
|
@ -51,9 +51,16 @@ export class Pax8Client {
|
|||
}
|
||||
|
||||
const data = await res.json();
|
||||
// WR-03: a 200 response with an unexpected body shape (proxy/CDN error
|
||||
// page reshaped as JSON, a future API version renaming the field, etc.)
|
||||
// must not silently set accessToken to undefined and mask the failure
|
||||
// behind a confusing 401 from the data endpoint later.
|
||||
if (!data.access_token || typeof data.expires_in !== 'number') {
|
||||
throw new Error('PAX8 token response missing access_token/expires_in');
|
||||
}
|
||||
this.accessToken = data.access_token;
|
||||
this.tokenExpiry = Date.now() + data.expires_in * 1000;
|
||||
return this.accessToken!;
|
||||
return this.accessToken;
|
||||
}
|
||||
|
||||
// Phase 11/12 will extend this with 429-aware Retry-After backoff for the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue