score:0

Accepted answer

well, i managed to find the solution on my own.

it's a little bit counter-intuitive, but to get the desired behavior you should just directly set the value of statuscode of the res object coming into getinitialprops of the said _error.tsx page.

along these lines:

errorpage.getinitialprops = ({ res, err }: nextpagecontext) => {
  const statuscode =
    (err as axioserror)?.response?.status ?? res?.statuscode ?? err?.statuscode ?? undefined;
  if (res && statuscode) {
    res.statuscode = statuscode;
  }
  const text = string(res?.statusmessage || err?.message || err);
  return { statuscode, text };
};


Related Query

More Query from same tag