request.ts raw

   1  import { WailsRequestRouter } from "wailsjs/go/wails/WailsApp";
   2  
   3  export const request = async <T>(
   4    ...args: Parameters<typeof fetch>
   5  ): Promise<T | undefined> => {
   6    try {
   7      const res = await WailsRequestRouter(
   8        args[0].toString(),
   9        args[1]?.method || "GET",
  10        args[1]?.body?.toString() || ""
  11      );
  12  
  13      console.info("Wails request", args[0].toString(), args[1]?.method || "GET");
  14      if (res.error) {
  15        throw new Error(res.error);
  16      }
  17  
  18      return res.body;
  19    } catch (error) {
  20      console.error("Failed to fetch", error);
  21      throw error;
  22    }
  23  };
  24