refactor: if we have an error, return a plain text response

This commit is contained in:
Derrick Hammer 2023-07-31 12:57:32 -04:00
parent 17030f285b
commit ff6d0ec036
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 2 deletions

View File

@ -5,19 +5,19 @@ import type {
OnBeforeSendHeadersDetailsType, OnBeforeSendHeadersDetailsType,
OnHeadersReceivedDetailsType, OnHeadersReceivedDetailsType,
OnRequestDetailsType, OnRequestDetailsType,
StreamFilter,
} from "../types.js"; } from "../types.js";
import { getRelayProxies } from "../util.js"; import { getRelayProxies } from "../util.js";
import { ipfsPath, ipnsPath, path as checkPath } from "is-ipfs"; import { ipfsPath, ipnsPath, path as checkPath } from "is-ipfs";
import { createClient } from "@lumeweb/kernel-ipfs-client"; import { createClient } from "@lumeweb/kernel-ipfs-client";
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
import type { DNSResult } from "@lumeweb/libresolver"; import type { DNSResult } from "@lumeweb/libresolver";
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
import RequestStream from "../requestStream.js"; import RequestStream from "../requestStream.js";
import type { UnixFSStats } from "@helia/unixfs"; import type { UnixFSStats } from "@helia/unixfs";
import * as path from "path"; import * as path from "path";
import { CID } from "multiformats/cid"; import { CID } from "multiformats/cid";
import { fileTypeFromBuffer } from "file-type"; import { fileTypeFromBuffer } from "file-type";
import extToMimes from "../mimes.js"; import extToMimes from "../mimes.js";
import { stringToUint8Array } from "binconv";
export default class IpfsProvider extends BaseProvider { export default class IpfsProvider extends BaseProvider {
private _client = createClient(); private _client = createClient();
@ -115,6 +115,9 @@ export default class IpfsProvider extends BaseProvider {
reqStream.start(); reqStream.start();
if (err) { if (err) {
const streamWriter = reqStream.stream.writable.getWriter();
streamWriter.write(stringToUint8Array("failed loading web3 page"));
streamWriter.releaseLock();
reqStream.close(); reqStream.close();
return {}; return {};
} }