async function nsoneRequest()

in src/nsone.ts [5:26]


async function nsoneRequest<T extends object>(
	logger: Logger,
	method: string,
	url: string,
	apiKey: string,
): Promise<T> {
	const headers = {
		'X-NSONE-Key': apiKey,
	};
	const fullUrl = `${apiPrefix}${url}`;
	logger.info('Making request to NSone', method, fullUrl);

	const response = await fetch(fullUrl, { method, headers });

	if (response.ok) {
		const json = (await response.json()) as unknown;
		return json as T;
	}

	logger.info(`Error ${response.status}: ${await response.text()}`);
	throw new Error('Non 200 status code returned from request');
}