export default async function fetchAPI ( path = '/' , method = 'GET' , body = { } ) { const API = '/api' ; let err ; let ops = { headers : { Accept : 'application/json' , 'Content-Type' : 'application/json; charset=utf-8' , } , method , } ; if ( ( body && method === 'POST' ) || method === 'PATCH' ) { ops . body = JSON . stringify ( body ) ; } try { const res = await fetch ( `${ API }${ path }` , ops ) ; const data = await res . json ( ) ; return data ; } catch ( e ) { if ( e . message === 'cancelled' ) { console . log ( 'Request Cancelled by the Browser ' , e ) ; err = e ; } else { console . error ( 'Network Error, CORS or timeout.' ) ; } } }