Skip to content

Commit

Permalink
wip-fix: client node-fetch http connection reset errors (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiroaisen authored Apr 15, 2024
2 parents 0f5519f + 2cd3903 commit cd242d1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion front/admin/src/lib/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const load_call = async <T>(
}
}
} catch(e: any) {
console.log(e);
const api_error = new ApiError(502, "FRONT_GATEWAY_FETCH", `Bad gateway (fetch)`);
error(api_error.status as NumericRange<400, 599>, api_error.toJSON().error);
}
Expand Down
2 changes: 1 addition & 1 deletion front/packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openstream/client",
"version": "0.3.2",
"version": "0.3.3",
"description": "Openstream Radio Server Client",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion front/packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const qss = (v: any) => {
return qs.stringify(v, { addQueryPrefix: true, skipNulls: true })
}

const http_agent = new http.Agent({ keepAlive: true });
const https_agent = new https.Agent({ keepAlive: true });

export class Client {

private base_url: string;
Expand Down Expand Up @@ -64,7 +67,7 @@ export class Client {
const method = init.method ?? "GET";
// this.logger.debug(`fetch: ${method} ${url}`);
return await this.node_fetch(url, {
agent: (url) => url.protocol === "http:" ? http.globalAgent : https.globalAgent,
agent: (url) => url.protocol === "http:" ? http_agent : https_agent,
...init
}).catch(e => {
// this.logger.warn(`fetch error: ${e} | cause=${e.cause}`)
Expand Down
14 changes: 7 additions & 7 deletions front/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion front/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@openstream/client": "^0.3.2",
"@openstream/client": "^0.3.3",
"accept-language-parser": "^1.5.0",
"braintree": "^3.15.0",
"commander": "^9.4.1",
Expand Down

0 comments on commit cd242d1

Please sign in to comment.