const wrap = < T > ( task ) : Promise < T > => { return new Promise ( ( resolve , reject ) => { task . then ( ( response ) => { if ( response . ok ) { response . json ( ) . then ( ( json ) => { resolve ( json ) ; } ) . catch ( ( error ) => { reject ( error ) ; } ) ; } else { reject ( response ) ; } } ) . catch ( ( error ) => { reject ( error ) ; } ) ; } ) ; } ; const fetcher = < T = any > ( url , init = { } ) : Promise < T > => { const requestHeaders = new Headers ( ) ; requestHeaders . append ( 'x-api-key' , process . env . NEXT_PUBLIC_API_KEY ! ) ; init . headers = requestHeaders ; return wrap < T > ( fetch ( url , init ) ) ; } ; export default fetcher ;