Skip to content

Commit fe98f98

Browse files
committed
Explicitly throw error on gunzip failure to prevent uncaught exception (#4873, #4874).
1 parent 243cb02 commit fe98f98

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src.ts/utils/geturl.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,18 @@ export function createGetUrl(options?: Record<string, any>): FetchGetUrlFunc {
101101
});
102102

103103
resp.on("end", () => {
104-
if (headers["content-encoding"] === "gzip" && body) {
105-
body = getBytes(gunzipSync(body));
106-
}
104+
try {
105+
if (headers["content-encoding"] === "gzip" && body) {
106+
body = getBytes(gunzipSync(body));
107+
}
107108

108-
resolve({ statusCode, statusMessage, headers, body });
109+
resolve({ statusCode, statusMessage, headers, body });
110+
111+
} catch (error) {
112+
reject(makeError("bad response data", "SERVER_ERROR", {
113+
request: req, info: { response: resp, error }
114+
}));
115+
}
109116
});
110117

111118
resp.on("error", (error) => {

0 commit comments

Comments
 (0)