Merge pull request #282 from Permissionless-Software-Foundation/ct-unstable

fix(psf-slp-indexer): Fixing issue with error handling
This commit is contained in:
Chris Troutner
2025-12-29 13:52:40 -07:00
committed by GitHub
2 changed files with 13 additions and 13 deletions
+5 -5
View File
@@ -66,7 +66,7 @@ class PsfSlpIndexer {
) )
return response.data return response.data
} catch (error) { } 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 else throw error
} }
} }
@@ -134,7 +134,7 @@ class PsfSlpIndexer {
} }
throw new Error('Input address must be a string.') throw new Error('Input address must be a string.')
} catch (error) { } 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 else throw error
} }
} }
@@ -199,7 +199,7 @@ class PsfSlpIndexer {
} }
throw new Error('Input tokenId must be a string.') throw new Error('Input tokenId must be a string.')
} catch (error) { } 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 else throw error
} }
} }
@@ -427,7 +427,7 @@ class PsfSlpIndexer {
} }
throw new Error('Input tokenId must be a string.') throw new Error('Input tokenId must be a string.')
} catch (error) { } 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 else throw error
} }
} }
@@ -522,7 +522,7 @@ class PsfSlpIndexer {
throw new Error('Input tokenId must be a string.') throw new Error('Input tokenId must be a string.')
} catch (error) { } catch (error) {
// console.log('error: ', 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 else throw error
} }
} }
+8 -8
View File
@@ -43,14 +43,14 @@ describe('#PsfSlpIndexer', () => {
try { try {
// Stub the network call. // Stub the network call.
const testErr = new Error() const testErr = new Error()
testErr.response = { data: { status: 422 } } testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'get').throws(testErr) sandbox.stub(axios, 'get').throws(testErr)
await bchjs.PsfSlpIndexer.status() await bchjs.PsfSlpIndexer.status()
// console.log(`result: ${JSON.stringify(result, null, 2)}`) // console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(true, false, 'Unexpected result!') assert.equal(true, false, 'Unexpected result!')
} catch (err) { } catch (err) {
assert.equal(err.status, 422) assert.equal(err.message, 'Status 422')
} }
}) })
}) })
@@ -103,7 +103,7 @@ describe('#PsfSlpIndexer', () => {
try { try {
// Stub the network call. // Stub the network call.
const testErr = new Error() const testErr = new Error()
testErr.response = { data: { status: 422 } } testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'post').throws(testErr) sandbox.stub(axios, 'post').throws(testErr)
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n' const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
@@ -112,7 +112,7 @@ describe('#PsfSlpIndexer', () => {
// console.log(`result: ${JSON.stringify(result, null, 2)}`) // console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(true, false, 'Unexpected result!') assert.equal(true, false, 'Unexpected result!')
} catch (err) { } catch (err) {
assert.equal(err.status, 422) assert.equal(err.message, 'Status 422')
} }
}) })
}) })
@@ -174,7 +174,7 @@ describe('#PsfSlpIndexer', () => {
try { try {
// Stub the network call. // Stub the network call.
const testErr = new Error() const testErr = new Error()
testErr.response = { data: { status: 422 } } testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'post').throws(testErr) sandbox.stub(axios, 'post').throws(testErr)
const tokenId = const tokenId =
@@ -182,7 +182,7 @@ describe('#PsfSlpIndexer', () => {
await bchjs.PsfSlpIndexer.tokenStats(tokenId) await bchjs.PsfSlpIndexer.tokenStats(tokenId)
assert.equal(true, false, 'Unexpected result!') assert.equal(true, false, 'Unexpected result!')
} catch (err) { } catch (err) {
assert.equal(err.status, 422) assert.equal(err.message, 'Status 422')
} }
}) })
}) })
@@ -399,7 +399,7 @@ describe('#PsfSlpIndexer', () => {
try { try {
// Stub the network call. // Stub the network call.
const testErr = new Error() const testErr = new Error()
testErr.response = { data: { status: 422 } } testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'post').throws(testErr) sandbox.stub(axios, 'post').throws(testErr)
const tokenId = const tokenId =
@@ -407,7 +407,7 @@ describe('#PsfSlpIndexer', () => {
await bchjs.PsfSlpIndexer.getTokenData(tokenId) await bchjs.PsfSlpIndexer.getTokenData(tokenId)
assert.equal(true, false, 'Unexpected result!') assert.equal(true, false, 'Unexpected result!')
} catch (err) { } catch (err) {
assert.equal(err.status, 422) assert.equal(err.message, 'Status 422')
} }
}) })
}) })