passlet 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/dist/index.cjs +14 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/package.json +20 -16
package/dist/index.js
CHANGED
|
@@ -432,7 +432,7 @@ async function getAccessToken(credentials, privateKey) {
|
|
|
432
432
|
const text = await response.text();
|
|
433
433
|
throw new WalletError(
|
|
434
434
|
"GOOGLE_API_ERROR",
|
|
435
|
-
`Failed to obtain access token (${response.status}): ${text}`
|
|
435
|
+
`Failed to obtain access token (${response.status}): ${extractGoogleDetail(text)}`
|
|
436
436
|
);
|
|
437
437
|
}
|
|
438
438
|
const data = await response.json();
|
|
@@ -453,12 +453,23 @@ async function walletRequest(method, path, credentials, privateKey, body) {
|
|
|
453
453
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
454
454
|
});
|
|
455
455
|
}
|
|
456
|
+
function extractGoogleDetail(text) {
|
|
457
|
+
try {
|
|
458
|
+
const body = JSON.parse(text);
|
|
459
|
+
if (body.error?.message) {
|
|
460
|
+
return body.error.message;
|
|
461
|
+
}
|
|
462
|
+
} catch {
|
|
463
|
+
}
|
|
464
|
+
return text;
|
|
465
|
+
}
|
|
456
466
|
async function assertOk(response) {
|
|
457
467
|
if (!response.ok) {
|
|
458
468
|
const text = await response.text();
|
|
469
|
+
const detail = extractGoogleDetail(text);
|
|
459
470
|
throw new WalletError(
|
|
460
471
|
"GOOGLE_API_ERROR",
|
|
461
|
-
`Google Wallet API error (${response.status}): ${
|
|
472
|
+
`Google Wallet API error (${response.status}): ${detail}`
|
|
462
473
|
);
|
|
463
474
|
}
|
|
464
475
|
}
|
|
@@ -477,7 +488,7 @@ async function ensureClass(classType, classId, classBody, credentials, privateKe
|
|
|
477
488
|
const text = await existing.text();
|
|
478
489
|
throw new WalletError(
|
|
479
490
|
"GOOGLE_API_ERROR",
|
|
480
|
-
`Google Wallet API error (${existing.status}): ${text}`
|
|
491
|
+
`Google Wallet API error (${existing.status}): ${extractGoogleDetail(text)}`
|
|
481
492
|
);
|
|
482
493
|
}
|
|
483
494
|
await assertOk(
|