src/api.js
// Send a request to the specified URL with the bearer token and obtain the response as JSON.
Send a request to the specified URL with the bearer token and obtain the response as JSON.
Send a request to the specified URL with the bearer token and obtain the response as JSON .
async function fetchWithToken(url, token) {
  const response = await fetch(url, {
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    }
  });
  const json = await response.json();
  if (json.error) {
    let err;
    if (typeof json.error === 'object') {
      err = new Error(`${json.error.status} ${json.error.message}`);
    } else {
      err = new Error(json.error_description);
    }
    err.object = json;
    throw err;
  }
  return json;
}
async function fetchWithToken ( url , token ) { const response = await fetch ( url , { headers : { 'Authorization' : ` ${ token } ` , 'Content-Type' : 'application/json' } } ) ; const json = await response . json ( ) ; if ( json . error ) { let err ; if ( typeof json . error === 'object' ) { err = new Error ( ` ${ json . error . status } ${ json . error . message } ` ) ; } else { err = new Error ( json . error_description ) ; } err . object = json ; throw err ; } return json ; }
Send a request to the specified URL with the bearer token and obtain the response as JSON.
Send a request to the specified URL with the bearer token and obtain the response as JSON .