When Pages Function is faces an issue of getting a response from the external endpoint, it throws 50

When Pages Function is faces an issue of getting a response from the external endpoint, it throws 500 Internal error which basically crashes my frontend. How can I capture this error and throw an appropriate error response to handle in my frontend?
when I try to fetch from the endpoint, I can't even get a res to do that. Or is there a way and I am missing something?
Was this page helpful?