FrontEnd.ro logo
async-await
async function fetchUser(username) {
  try {
    let userResp = await fetch(`/api/users/${username}`);
    let userJSON = await userResp.json();
    let teamJSON = null;

    if (userJSON.team !== undefined) {
      let teamResp = await fetch(`/api/teams/${userJSON.team}`);
      teamJSON = await teamResp.json();
    }

    return {
      user: userJSON,
      team: teamJSON,
    };
  } catch (err) {
    console.error('Something went wrong', err);
  }
}