From 64beb77195488abc0ea6d67acc5c4006d28d4bb1 Mon Sep 17 00:00:00 2001 From: tchardin Date: Wed, 11 Oct 2023 16:32:28 -0600 Subject: [PATCH] fix: throw when jwt is null --- src/utils/jwt.js | 4 +++- test/index.spec.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/jwt.js b/src/utils/jwt.js index a63632e..ca72262 100644 --- a/src/utils/jwt.js +++ b/src/utils/jwt.js @@ -30,7 +30,9 @@ export async function getJWT (opts, storage) { const url = `${authURL}?clientKey=${clientKey}` const result = await fetch(url) - const { token } = await result.json() + const { token, message } = await result.json() + + if (!token) throw new Error(message || 'Failed to refresh jwt') try { await storage.set(JWT_KEY, token) diff --git a/test/index.spec.js b/test/index.spec.js index e699bf5..66b537e 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -6,7 +6,7 @@ import Saturn from '#src/index.js' const TEST_CID = 'QmXjYBY478Cno4jzdCcPy4NcJYFrwHZ51xaCP8vUwN9MGm' -const clientKey = '1234567890abcdef' +const clientKey = 'abc123' describe('Saturn client', () => { describe('constructor', () => {