Try Catch in Express Endpoint Function Causes Hanging Deployment
a-r-t
FREEOP

10 months ago

I have an extremely simple test express app. I have a simple GET route setup:

app.get('/ping', (req, res) => {
  try {
    res.status(200).json({ message: 'pong' })
  }
  catch(err) {
    res.status(500).json({ error: 'something went wrong' })
  }
})

This code builds fine, but causes the deployment to hang indefinitely (it never starts my server, and no logs are provided).

If I remove the try catch, things work fine (server is started, everything is successful, I can call API):

app.get('/ping', (req, res) => {
    return res.status(200).json({ message: 'pong' })
})

I know the try catch doesn't do anything in this situation, but I will want the try catches for when I implement my actual app, and this is a pretty common pattern, so I'm unsure why that would cause things to go so badly that the deployment can't even start. Any help would be greatly appreciated!

PS: I've tried adding async, removing the return statement, etc. -- all same result; work fine without try catch, hang deployment with no logs with try catch. Everything works fine locally.

Solved

4 Replies

10 months ago

Hello,

The domain works fine for me.

Can you be more specific with your issue?

Best,
Brody


Status changed to Awaiting User Response Railway 10 months ago


a-r-t
FREEOP

10 months ago

I literally just re-pushed the same code I've been trying to get working for hours and it worked now, no idea why. Not sure if it's worth you looking at my past deployments to try to figure out what happened, but seems okay now?


Status changed to Awaiting Railway Response Railway 10 months ago


a-r-t
FREEOP

10 months ago

Maybe something is just going on with deployments today? I have another hanging deployment, despite not changing any code from the previous working one...possible the try catch and all that was just a red herring


10 months ago

Then it was likely related to this incident - https://status.railway.com/cma2xgdyx001s172fcvs2e7e9

If you have any in-flight deploys you will need to cancel them and redeploy.


Status changed to Awaiting User Response Railway 10 months ago


Railway
BOT

7 months ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 7 months ago


Loading...