Skip to content

Commit

Permalink
fix: log correct response status (#48)
Browse files Browse the repository at this point in the history
When the second request fails, log the status of the second request, not the first.
  • Loading branch information
achingbrain authored Dec 11, 2024
1 parent 418714c commit e23855b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
node-version: lts/*
- run: npm i
working-directory: ./examples
- uses: ipfs/aegir/actions/cache-node-modules@master
- uses: ipfs/aegir/actions/cache-node-modules@main
with:
directories: |
./examples/node_modules
Expand All @@ -30,7 +30,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- uses: ipfs/aegir/actions/cache-node-modules@main
with:
directories: |
./examples/node_modules
Expand Down
2 changes: 1 addition & 1 deletion src/auth/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class ClientAuth {
const resp2 = await fetch(request)

if (!resp2.ok) {
throw new BadResponseError(`Unexpected status code ${resp.status}`)
throw new BadResponseError(`Unexpected status code ${resp2.status}`)
}

const serverAuthHeader = resp2.headers.get('Authentication-Info')
Expand Down
12 changes: 8 additions & 4 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isPeerId, start, stop } from '@libp2p/interface'
import { streamPair } from '@libp2p/interface-compliance-tests/mocks'
import { defaultLogger } from '@libp2p/logger'
import { peerIdFromString } from '@libp2p/peer-id'
import { multiaddr, type Multiaddr, type Protocol } from '@multiformats/multiaddr'
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import { duplexPair } from 'it-pair/duplex'
import { type Libp2p } from 'libp2p'
Expand Down Expand Up @@ -45,20 +45,24 @@ describe('whatwg-fetch', () => {

let serverCB: StreamHandler
const serverCBRegistered = pDefer()
serverComponents.registrar.handle.callsFake(async (protocol: Protocol, cb: StreamHandler) => {
serverComponents.registrar.handle.callsFake(async (protocol: string, cb: StreamHandler) => {
serverCB = cb
serverCBRegistered.resolve()
})

const conn = stubInterface<Connection>()
conn.newStream.callsFake(async (protos: Protocol[], options?: any) => {
conn.newStream.callsFake(async (protos: string | string[], options?: any) => {
const duplexes = duplexPair<any>()
const streams = streamPair({ duplex: duplexes[0] }, { duplex: duplexes[1] })
serverCB({ stream: streams[0], connection: conn })
return streams[1]
})

clientComponents.connectionManager.openConnection.callsFake(async (peer: PeerId | Multiaddr, options?: any) => {
clientComponents.connectionManager.openConnection.callsFake(async (peer: PeerId | Multiaddr | Multiaddr[], options?: any) => {
if (Array.isArray(peer)) {
peer = peer[0]
}

if (isPeerId(peer) ? peer.equals(serverPeerID) : peer.getPeerId() === serverMultiaddr.getPeerId()) {
await serverCBRegistered.promise
return conn
Expand Down

0 comments on commit e23855b

Please sign in to comment.