502 error on exception in getServerSideProps
See original GitHub issueBug report
Describe the bug
When an exception is thrown in getServerSideProps in a serverless environment, the response is returned with a status code of 502 (Bad Gateway), which is definitely not what it is. In addition, custom or default 500 pages do not render in this case so the user may see a stack trace depending on how or where the app is deployed in production. This appears to be a Next 9.5+ issue, as it returned a 500 status code and a proper error page with the same code in 9.4.x.
To Reproduce
This will happen with any page that encounters an error in getServerSideProps. I’ve created a sample repo here with a “problem” page:
https://github.com/spencewood/throw-app
This simply includes:
import React from "react";
export default function Problem() {
return (
<>
<h1>Problem!</h1>
</>
);
}
export const getServerSideProps = () => {
throw new Error("error");
};
This page deployed to vercel: https://throw-app.vercel.app/problem
And curl:
❯ curl -I "https://throw-app.vercel.app/problem"
HTTP/2 502
date: Fri, 07 Aug 2020 18:20:24 GMT
content-type: text/plain; charset=utf-8
x-nextjs-page: /problem
content-length: 68
server: Vercel
x-vercel-id: cle1::2cxmx-1596824424449-1d2c09ffce13
strict-transport-security: max-age=63072000; includeSubDomains; preload
cache-control: s-maxage=0
Expected behavior
Simply downgrading the above app to Next 9.4 will correctly render the default 500 page for Next and will return a 500 status code. This is what should be happening, as a 500 indicates simply “server error” and 502 indicates “invalid/no response”.
Screenshots
Below are screenshots from https://throw-app.vercel.app/problem with source here: https://github.com/spencewood/throw-app
Next 9.4
Next 9.5
Other Thoughts
Obviously you’re not going to throw an error like this, but any exceptions thrown while server-side generating dynamic data to be delivered to the app will cause the 502.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:40
- Comments:13 (3 by maintainers)
Top GitHub Comments
Same problem here ! Plus, can’t see exception logs.
Running into the same issue - local production build displays my
_errors.tsx
but Vercel doesn’t. Are there any updates on this? Thanks!