#trouble with fetch and async

1 messages · Page 1 of 1 (latest)

nimble lily
#

Im trying to call the set_name function from the connect which then makes a fetch request. My goal is to be able to catch if the request errors out, and when it does to return from the connect function. Here are the two functions:

  if (!connected){
    await get_key();
  }

  connection_status = await get_status()

  // if in room then don't set name
  if (!connection_status.Connected){
    try{
      await set_name(user_name, user_color);
    }
    catch (error) {
      console.log(error);
      return;
    }

  }

  await join_theme(theme);
}```

```async function set_name(name, color){
    await fetch('/system/set_name', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'key': key
        },
        body: JSON.stringify({
          Name: name,
          Color: color
        })
      });
}```
nimble lily
#

nvm