From e2ca3cfb0036b3fd3f55e8c87171414369467f9f Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 29 Dec 2025 12:38:30 -0700 Subject: [PATCH] fix(psf-slp-indexer): Fixing issue with error handling --- src/psf-slp-indexer.js | 10 +++++----- test/unit/psf-slp-indexer.js | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/psf-slp-indexer.js b/src/psf-slp-indexer.js index 819b899..dde5749 100644 --- a/src/psf-slp-indexer.js +++ b/src/psf-slp-indexer.js @@ -66,7 +66,7 @@ class PsfSlpIndexer { ) return response.data } catch (error) { - if (error.response && error.response.data) throw error.response.data + if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error) else throw error } } @@ -134,7 +134,7 @@ class PsfSlpIndexer { } throw new Error('Input address must be a string.') } catch (error) { - if (error.response && error.response.data) throw error.response.data + if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error) else throw error } } @@ -199,7 +199,7 @@ class PsfSlpIndexer { } throw new Error('Input tokenId must be a string.') } catch (error) { - if (error.response && error.response.data) throw error.response.data + if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error) else throw error } } @@ -427,7 +427,7 @@ class PsfSlpIndexer { } throw new Error('Input tokenId must be a string.') } catch (error) { - if (error.response && error.response.data) throw error.response.data + if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error) else throw error } } @@ -522,7 +522,7 @@ class PsfSlpIndexer { throw new Error('Input tokenId must be a string.') } catch (error) { // console.log('error: ', error) - if (error.response && error.response.data) throw error.response.data + if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error) else throw error } } diff --git a/test/unit/psf-slp-indexer.js b/test/unit/psf-slp-indexer.js index d552b42..2f1daa1 100644 --- a/test/unit/psf-slp-indexer.js +++ b/test/unit/psf-slp-indexer.js @@ -43,14 +43,14 @@ describe('#PsfSlpIndexer', () => { try { // Stub the network call. const testErr = new Error() - testErr.response = { data: { status: 422 } } + testErr.response = { data: { error: 'Status 422' } } sandbox.stub(axios, 'get').throws(testErr) await bchjs.PsfSlpIndexer.status() // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.equal(err.status, 422) + assert.equal(err.message, 'Status 422') } }) }) @@ -103,7 +103,7 @@ describe('#PsfSlpIndexer', () => { try { // Stub the network call. const testErr = new Error() - testErr.response = { data: { status: 422 } } + testErr.response = { data: { error: 'Status 422' } } sandbox.stub(axios, 'post').throws(testErr) const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n' @@ -112,7 +112,7 @@ describe('#PsfSlpIndexer', () => { // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.equal(err.status, 422) + assert.equal(err.message, 'Status 422') } }) }) @@ -174,7 +174,7 @@ describe('#PsfSlpIndexer', () => { try { // Stub the network call. const testErr = new Error() - testErr.response = { data: { status: 422 } } + testErr.response = { data: { error: 'Status 422' } } sandbox.stub(axios, 'post').throws(testErr) const tokenId = @@ -182,7 +182,7 @@ describe('#PsfSlpIndexer', () => { await bchjs.PsfSlpIndexer.tokenStats(tokenId) assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.equal(err.status, 422) + assert.equal(err.message, 'Status 422') } }) }) @@ -399,7 +399,7 @@ describe('#PsfSlpIndexer', () => { try { // Stub the network call. const testErr = new Error() - testErr.response = { data: { status: 422 } } + testErr.response = { data: { error: 'Status 422' } } sandbox.stub(axios, 'post').throws(testErr) const tokenId = @@ -407,7 +407,7 @@ describe('#PsfSlpIndexer', () => { await bchjs.PsfSlpIndexer.getTokenData(tokenId) assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.equal(err.status, 422) + assert.equal(err.message, 'Status 422') } }) })