Skip to content

Commit e23855b

Browse files
authored
fix: log correct response status (#48)
When the second request fails, log the status of the second request, not the first.
1 parent 418714c commit e23855b

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

.github/workflows/test-examples.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
node-version: lts/*
1818
- run: npm i
1919
working-directory: ./examples
20-
- uses: ipfs/aegir/actions/cache-node-modules@master
20+
- uses: ipfs/aegir/actions/cache-node-modules@main
2121
with:
2222
directories: |
2323
./examples/node_modules
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions/setup-node@v4
3131
with:
3232
node-version: lts/*
33-
- uses: ipfs/aegir/actions/cache-node-modules@master
33+
- uses: ipfs/aegir/actions/cache-node-modules@main
3434
with:
3535
directories: |
3636
./examples/node_modules

src/auth/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class ClientAuth {
189189
const resp2 = await fetch(request)
190190

191191
if (!resp2.ok) {
192-
throw new BadResponseError(`Unexpected status code ${resp.status}`)
192+
throw new BadResponseError(`Unexpected status code ${resp2.status}`)
193193
}
194194

195195
const serverAuthHeader = resp2.headers.get('Authentication-Info')

test/index.spec.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isPeerId, start, stop } from '@libp2p/interface'
44
import { streamPair } from '@libp2p/interface-compliance-tests/mocks'
55
import { defaultLogger } from '@libp2p/logger'
66
import { peerIdFromString } from '@libp2p/peer-id'
7-
import { multiaddr, type Multiaddr, type Protocol } from '@multiformats/multiaddr'
7+
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
88
import { expect } from 'aegir/chai'
99
import { duplexPair } from 'it-pair/duplex'
1010
import { type Libp2p } from 'libp2p'
@@ -45,20 +45,24 @@ describe('whatwg-fetch', () => {
4545

4646
let serverCB: StreamHandler
4747
const serverCBRegistered = pDefer()
48-
serverComponents.registrar.handle.callsFake(async (protocol: Protocol, cb: StreamHandler) => {
48+
serverComponents.registrar.handle.callsFake(async (protocol: string, cb: StreamHandler) => {
4949
serverCB = cb
5050
serverCBRegistered.resolve()
5151
})
5252

5353
const conn = stubInterface<Connection>()
54-
conn.newStream.callsFake(async (protos: Protocol[], options?: any) => {
54+
conn.newStream.callsFake(async (protos: string | string[], options?: any) => {
5555
const duplexes = duplexPair<any>()
5656
const streams = streamPair({ duplex: duplexes[0] }, { duplex: duplexes[1] })
5757
serverCB({ stream: streams[0], connection: conn })
5858
return streams[1]
5959
})
6060

61-
clientComponents.connectionManager.openConnection.callsFake(async (peer: PeerId | Multiaddr, options?: any) => {
61+
clientComponents.connectionManager.openConnection.callsFake(async (peer: PeerId | Multiaddr | Multiaddr[], options?: any) => {
62+
if (Array.isArray(peer)) {
63+
peer = peer[0]
64+
}
65+
6266
if (isPeerId(peer) ? peer.equals(serverPeerID) : peer.getPeerId() === serverMultiaddr.getPeerId()) {
6367
await serverCBRegistered.promise
6468
return conn

0 commit comments

Comments
 (0)