Skip to content

Commit

Permalink
chore: failing to create range resp logs error
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Mar 7, 2024
1 parent 121747b commit 05a6dfb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 5 additions & 5 deletions packages/verified-fetch/src/utils/responses.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ByteRangeContext } from './byte-range-context'
import type { SupportedBodyTypes } from '../types.js'
import type { Logger } from '@libp2p/interface'

function setField (response: Response, name: string, value: string | boolean): void {
Object.defineProperty(response, name, {
Expand Down Expand Up @@ -116,9 +117,10 @@ export function movedPermanentlyResponse (url: string, location: string, init?:

interface RangeOptions {
byteRangeContext: ByteRangeContext
log?: Logger
}

export function okRangeResponse (url: string, body: SupportedBodyTypes, { byteRangeContext }: RangeOptions, init?: ResponseOptions): Response {
export function okRangeResponse (url: string, body: SupportedBodyTypes, { byteRangeContext, log }: RangeOptions, init?: ResponseOptions): Response {
if (!byteRangeContext.isRangeRequest) {
return okResponse(url, body, init)
}
Expand All @@ -138,10 +140,8 @@ export function okRangeResponse (url: string, body: SupportedBodyTypes, { byteRa
'content-range': byteRangeContext.contentRangeHeaderValue
}
})
} catch (e) {
// TODO: should we return a different status code here?
// eslint-disable-next-line no-console
console.error('Invalid range request', e)
} catch (e: any) {
log?.error('failed to create range response', e)
return badRangeResponse(url, body, init)

Check warning on line 145 in packages/verified-fetch/src/utils/responses.ts

View check run for this annotation

Codecov / codecov/patch

packages/verified-fetch/src/utils/responses.ts#L144-L145

Added lines #L144 - L145 were not covered by tests
}

Expand Down
8 changes: 2 additions & 6 deletions packages/verified-fetch/src/verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class VerifiedFetch {
})
byteRangeContext.setBody(stream)
// if not a valid range request, okRangeRequest will call okResponse
const response = okRangeResponse(resource, byteRangeContext.getBody(), { byteRangeContext }, {
const response = okRangeResponse(resource, byteRangeContext.getBody(), { byteRangeContext, log: this.log }, {
redirected
})

Expand All @@ -381,13 +381,9 @@ export class VerifiedFetch {
const byteRangeContext = new ByteRangeContext(this.helia.logger, options?.headers)
const result = await this.helia.blockstore.get(cid, options)
byteRangeContext.setBody(result)
const response = okRangeResponse(resource, byteRangeContext.getBody(), { byteRangeContext }, {
const response = okRangeResponse(resource, byteRangeContext.getBody(), { byteRangeContext, log: this.log }, {
redirected: false
})
// if (byteRangeContext.isRangeRequest) {
// } else {
// response = okResponse(resource, result)
// }

// if the user has specified an `Accept` header that corresponds to a raw
// type, honour that header, so for example they don't request
Expand Down

0 comments on commit 05a6dfb

Please sign in to comment.