Skip to content

Commit a474021

Browse files
committed
fix : check response status before returning
1 parent 8b64533 commit a474021

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

.changeset/tiny-crabs-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"leetcode-query": patch
3+
---
4+
5+
Check response status before returning GraphQL data

src/leetcode-cn.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ export class LeetCodeCN extends EventEmitter {
119119
},
120120
body: JSON.stringify(query),
121121
});
122+
if (!res.ok) {
123+
throw new Error(`HTTP ${res.status} ${res.statusText}: ${await res.text()}`);
124+
}
125+
122126
this.emit("receive-graphql", res.clone());
123127

124128
if (res.headers.has("set-cookie")) {

src/leetcode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ export class LeetCode extends EventEmitter {
364364
},
365365
body: JSON.stringify(query),
366366
});
367+
if (!res.ok) {
368+
throw new Error(`HTTP ${res.status} ${res.statusText}: ${await res.text()}`);
369+
}
370+
367371
this.emit("receive-graphql", res.clone());
368372

369373
if (res.headers.has("set-cookie")) {

tsup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export default defineConfig((options) => ({
77
format: ["cjs", "esm"],
88
clean: true,
99
splitting: false,
10-
minify: !options.watch,
1110
dts: options.watch ? false : { resolve: true },
1211
esbuildOptions(opt) {
1312
opt.loader = {

0 commit comments

Comments
 (0)