# "504 Gateway Time-out" during token exchange

**URL:** <https://forum.asana.com/t/504-gateway-time-out-during-token-exchange/92493>\
**Category:** API & Developers\
**Created:** [24 August 2020 14:43 UTC](https://forum.asana.com/t/504-gateway-time-out-during-token-exchange/92493 "2020-08-24T14:43:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_DeSilva](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/sean_desilva/32/60162_2.png) [@Sean\_DeSilva](https://forum.asana.com/u/Sean_DeSilva)\
**Post date:** [24 August 2020 14:43 UTC](https://forum.asana.com/t/504-gateway-time-out-during-token-exchange/92493/1 "2020-08-24T14:43:56Z")

</div>

Seen in browser main window:

```auto
504 Gateway Time-out
The server didn't respond in time.

```

I’m making the initial request to grant scopes from my front end react.js app. however the redirect uri is my backend Express.js API. The auth code to token exchange step is where this error is occuring.

Here is the route handler callback at this endpoint:

```auto
router.get('/authCode', async (req: Request, res: Response) => {
  const tokenExchangeEndpoint = 'https://app.asana.com/-/oauth_token';

  const tokenRequestBody: IAuthCodeRequest = {
    grant_type: EGrantTypes.authCode,
    client_id: process.env.ASANA_CLIENT_ID!,
    client_secret: process.env.ASANA_CLIENT_SECRET!,
    redirect_uri: process.env.ASANA_HTTPS_REDIRECT_URL!,
    code: req.query.code as string,
  };

  console.log('----------------------');
  console.log('tokenRequestBody', tokenRequestBody);
  console.log('----------------------');

  try {
    const response = await fetch(tokenExchangeEndpoint, {
      method: 'post',
      mode: 'cors',
      headers: {
        'content-type': 'application/json',
      },
      body: JSON.stringify(tokenRequestBody),
    });

    const tokenObject: ITokenResponseBody = await response.json();
    const { access_token, refresh_token } = tokenObject;
    const { id, name, email } = tokenObject.data;

    console.log('----------------------');
    console.log('tokenObject', tokenObject);
    console.log('----------------------');

```

The 2nd console block never prints to terminal. Here’s what I do see:

```auto
[nodemon] starting `node compiled/server.js`
Express server listening on port 6500
----------------------
tokenRequestBody {
  grant_type: 'authorization_code',
  client_id: '1188removed',
  client_secret: 'b2dremoved',
  redirect_uri: 'https://asanarepeater.ngrok.io/authCode',
  code: '1/111920removed'
}
----------------------
(node:29618) UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'id' of undefined
    at /home/owner/cp/project/compiled/oauth/router.js:136:23
    at step (/home/owner/cp/project/compiled/oauth/router.js:33:23)
    at Object.next (/home/owner/cp/project/compiled/oauth/router.js:14:53)
    at fulfilled (/home/owner/cp/project/compiled/oauth/router.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:29618) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:29618) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

```

The values look good to me, but this fetch request is timing out I think (since the console statements following it never print). Is there an error above?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 19:06 UTC](https://forum.asana.com/t/504-gateway-time-out-during-token-exchange/92493/2 "2025-05-30T19:06:35Z")

</div>

Closed on 30 May 2025 19:06 UTC


