Skip to content

Commit 35308b4

Browse files
authored
fix: client bubbles up errors (#166)
* fix: client bubbles up errors * chore: remove unused import * chore: remove catch block in findProviders
1 parent 01863c7 commit 35308b4

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/client/src/client.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
168168
} else {
169169
throw new BadResponseError(`Unsupported Content-Type: ${contentType}`)
170170
}
171-
} catch (err) {
172-
log.error('getProviders errored:', err)
173171
} finally {
174172
signal.clear()
175173
onFinish.resolve()

packages/client/test/routings.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,40 @@ describe('libp2p content-routing', () => {
8282
})))
8383
})
8484

85+
it('should respect abort signal when finding providers', async () => {
86+
const routing = getContentRouting(client)
87+
88+
if (routing == null) {
89+
throw new Error('ContentRouting not found')
90+
}
91+
92+
const providers = [{
93+
ID: (await generateKeyPair('Ed25519')).publicKey.toString(),
94+
Addrs: ['/ip4/43.43.43.43/tcp/1234']
95+
}]
96+
97+
const cid = CID.parse('QmawceGscqN4o8Y8Fv26UUmB454kn2bnkXV5tEQYc4jBd6')
98+
99+
// load providers for the router to fetch
100+
await fetch(`${process.env.ECHO_SERVER}/add-providers/${cid.toString()}`, {
101+
method: 'POST',
102+
body: providers.map(prov => JSON.stringify(prov)).join('\n')
103+
})
104+
105+
let findProvidersFinished = false
106+
let error: any = new Error('temporary error that should be replaced')
107+
try {
108+
const controller = new AbortController()
109+
controller.abort()
110+
await all(routing.findProviders(cid, { signal: controller.signal }))
111+
findProvidersFinished = true
112+
} catch (err: any) {
113+
error = err
114+
}
115+
expect(findProvidersFinished).to.be.false()
116+
expect(error).to.have.property('message').that.includes('abort', error.message)
117+
})
118+
85119
it('should provide without error', async () => {
86120
const routing = getContentRouting(client)
87121

0 commit comments

Comments
 (0)