Skip to content

Commit

Permalink
Add cancellation error handlings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomato6966 committed Oct 13, 2024
1 parent 45949e1 commit 7135650
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 29 deletions.
11 changes: 5 additions & 6 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { shouldUseGlobalFetchAndWebSocket } from "@discordjs/util";

// src/customNodeFetch.ts
import axios from "axios";
import { AbortError } from "@vladfrangu/async_event_emitter";
var normalizeHeaders = /* @__PURE__ */ __name((headers) => {
if (!headers) return new Headers();
const result = [];
Expand Down Expand Up @@ -80,9 +79,9 @@ var customFetch = /* @__PURE__ */ __name(async (input, options = {}) => {
}
if (error.response?.data) error.response.data = tryParse(error.response.data);
if (error.code === "ERR_CANCELED" || error.config?.signal?.aborted) {
throw new AbortError(error.message, {
...error
});
error.code = "ECONNRESET";
error.name = "AbortError";
throw error;
}
if (error.response) {
const { status, statusText, headers, data } = error.response;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions dist/web.js

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

2 changes: 1 addition & 1 deletion dist/web.js.map

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions dist/web.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:

// src/customNodeFetch.ts
import axios from "axios";
import { AbortError } from "@vladfrangu/async_event_emitter";
var normalizeHeaders = /* @__PURE__ */ __name((headers) => {
if (!headers) return new Headers();
const result = [];
Expand Down Expand Up @@ -75,9 +74,9 @@ var customFetch = /* @__PURE__ */ __name(async (input, options = {}) => {
}
if (error.response?.data) error.response.data = tryParse(error.response.data);
if (error.code === "ERR_CANCELED" || error.config?.signal?.aborted) {
throw new AbortError(error.message, {
...error
});
error.code = "ECONNRESET";
error.name = "AbortError";
throw error;
}
if (error.response) {
const { status, statusText, headers, data } = error.response;
Expand Down
2 changes: 1 addition & 1 deletion dist/web.mjs.map

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/customNodeFetch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import axios, { AxiosRequestConfig } from "axios";
import { HeadersInit, RequestInfo, RequestInit } from "undici";

import { AbortError } from "@vladfrangu/async_event_emitter";

import { ResponseLike } from "./shared";

const normalizeHeaders = (headers: Record<string, any>): HeadersInit => {
Expand Down Expand Up @@ -91,9 +89,9 @@ export const customFetch = async (input: RequestInfo | URL, options: RequestInit
if(error.response?.data) error.response.data = tryParse(error.response.data);

if(error.code === "ERR_CANCELED" || error.config?.signal?.aborted) {
throw new AbortError(error.message, {
...error,
})
error.code = "ECONNRESET";
error.name = "AbortError";
throw error;
}

if(error.response) {
Expand Down

0 comments on commit 7135650

Please sign in to comment.