import 'whatwg-fetch' ; export default function fetchCustom ( url , options ? ) { document . dispatchEvent ( new CustomEvent ( 'fetch:start' ) ) ; return ( fetch ( url , { headers : { 'Content-Type' : 'application/json' , Accept : 'application/json' , } , } ) . then ( response => response . json ( ) . then ( ( body ) => { if ( response . status >= 400 ) { return Promise . reject ( { status : response . status , payload : body . error } ) ; } return body ; } ) ) . then ( ( res ) => { document . dispatchEvent ( new CustomEvent ( 'fetch:done' ) ) ; return res ; } ) . catch ( ( err ) => { document . dispatchEvent ( new CustomEvent ( 'fetch:done' ) ) ; return Promise . reject ( err ) ; } ) ) ; }