@clipwhisperer/common
Version:
ClipWhisperer Common - Shared library providing core utilities, database schemas, authentication, bucket management, and common functionality across all ClipWhisperer microservices
25 lines (24 loc) • 729 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.request = request;
/**
*
* @param schema - The schema to parse the response with
* @param url - The URL to request
* @param headers - The headers to send with the request
* @returns The parsed response or null if the request fails
*/
async function request(schema, url, headers = {}) {
try {
const response = await fetch(url, { headers });
if (!response.ok) {
throw new Error(`Got HTTP error: ${response.statusText}, url: ${url}`);
}
const data = await response.json();
return schema.parse(data);
}
catch (error) {
console.error(error);
return null;
}
}