artemkorsakov_project-euler.../helpers/fetchUtils.ts
2025-03-15 12:02:19 +03:00

24 lines
659 B
TypeScript

import { requestUrl } from 'obsidian';
/**
* Function to perform a GET request with cookies.
* @param url - The URL to fetch.
* @param cookies - Cookies to include in the request headers.
* @returns The response text.
* @throws Error if the HTTP request fails.
*/
export async function fetchWithCookies(url: string, cookies: string): Promise<string> {
const response = await requestUrl({
url: url,
method: 'GET',
headers: {
'Cookie': cookies,
},
});
if (response.status !== 200) {
throw new Error(`HTTP error! GET ${url} status: ${response.status}.`);
}
return response.text;
}