Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
XInTheDark committed Nov 18, 2024
1 parent 9c72d04 commit dfee3a7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/api/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import default_fetch from "node-fetch";
import { HttpProxyAgent } from "http-proxy-agent";
import { Preferences } from "./preferences.js";

const devMode = Preferences["devMode"] || false;

/**
* Custom fetch function with optional proxy support
* @param {string} url - The URL to fetch
Expand All @@ -16,8 +18,19 @@ async function fetchWithProxy(url, options = {}, proxy = null) {
if (proxy) {
options.agent = new HttpProxyAgent(proxy);
}
if (devMode) {
console.log(`${options.method || "GET"} : ${url}, proxy: ${proxy}`);
}

const response = await default_fetch(url, options);
if (devMode) {
console.log(`response:\n ${response}, status: ${response.status} : ${response.statusText}`);
if (!response.ok) {
console.log(`error: ${await response.text()}`);
}
}

return default_fetch(url, options);
return response;
}

async function fetch(url, options = {}) {
Expand Down

0 comments on commit dfee3a7

Please sign in to comment.