gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { env } from '../env/index';
 
export async function fetchOrThrow(
  url: string,
  // eslint-disable-next-line no-undef
  init?: RequestInit,
): Promise<Response> {
  const { fetch } = env.getEnv();
  const res = await fetch(url, init);
  if (!(res.status < 400)) {
    throw new Error(`failed to fetch: (${res.status}) ${res.statusText}, from url: ${res.url}`);
  }
  return res;
}