import throwError from '../node/throwError'; export type WargamingResponse = | { status: 'error'; error: { field: string; message: string; code: 402; value: null }; } | { status: 'ok'; data: Data; }; export default async function getWargamingResponse( url: string, ) { let parsed: WargamingResponse; const response = await fetch(url); parsed = (await response.json()) as WargamingResponse; if (parsed.status === 'ok') { return parsed.data; } else { throw throwError( `Wargaming response error status:"${parsed.status}"`, `Message: "${parsed.error.message}"\nURL: "${url}"`, ); } }