INNER CODE UNIT · TypeScript

request

gadingnst/fullstack-next-template · src/packages/libs/BaseHttp/index.ts:58

  public async request(method: BaseHttpMethod, url: string, args?: Omit<RequestInit, 'method'>) {
    const endpoint = `${this.baseURL}${encodeURI(url).trim()}`;
    const response = await fetch(endpoint, {
      ...this.requestInit,
      ...args,
      headers: {
        'Content-Type': 'application/json',
        ...this.requestInit.headers,
        ...args?.headers,
      },
      method,
    });

    if (!response.ok) {
      const error = new Error(
        `HTTP (${method}) ${response.status} error. On: "${endpoint}"`
      ) as BaseHttpError;
      error.response = response;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…