mirror of
				https://github.com/khairul169/db-backup-tool.git
				synced 2025-11-04 13:41:06 +07:00 
			
		
		
		
	
		
			
				
	
	
		
			16 lines
		
	
	
		
			465 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			16 lines
		
	
	
		
			465 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { ClientResponse, hc } from "hono/client";
 | 
						|
import type { AppRouter } from "../../../backend/src/routers";
 | 
						|
 | 
						|
const api = hc<AppRouter>("http://localhost:3000/");
 | 
						|
 | 
						|
export const parseJson = async <T>(res: ClientResponse<T>) => {
 | 
						|
  const json = await res.json();
 | 
						|
  if (!res.ok) {
 | 
						|
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
 | 
						|
    throw new Error((json as any)?.message || "An error occured.");
 | 
						|
  }
 | 
						|
  return json as T;
 | 
						|
};
 | 
						|
 | 
						|
export default api;
 |