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 };
};
Source: stackoverflow.com
Related Query
- How to specify HTTP response code in next.js
- How do I get the HTTP response code from a successful React query?
- How do I show the user the specific http response code & message using React Hooks
- How to fetch response body using fetch in case of HTTP error 422?
- How to wait for .map() to finish executing before continuing on to next lines of code
- How to add http Headers in react js app's response
- How can i use my custom http error msg that are in the response body in react-admin
- How to catch HTTP response error and then pass to the caller
- How can I specify authentication globally instead of defining on every page in Next js, I am using next-auth package with react query
- How to make multiple HTTP requests with RxJS and merge the response into one payload and map it to another action?
- how to get response data in fetch if status code is 400 react js
- How to download .zip file that i recieve from a HTTP response (axios PUT request)
- How to hold for 5 sec after api response and then go next in react native
- How do you properly send a proper HTTP Response in CakePHP 3.5
- Yii2 and reactjs CORS filters gives Error: Response for preflight has invalid HTTP status code 401
- React Redux how to store http response in Reducer
- How do I get reponse data from 400 http response in ReactJS
- How can I assign data from Http response in const Component?
- How to execute some code after some specific HTTP verbs were executed
- How to use the cookie from an http response
- How can i use the useSWR hook when my response need to do some logical operations before next dependant API call
- How can I evaluate text response as code in Javascript/React
- How to setState depending on post http method response status?
- How to specify a port to run a create-react-app based project?
- Webpack how to build production code and how to use it
- How to specify (optional) default props with TypeScript for stateless, functional React components?
- How to make Jest wait for all asynchronous code to finish execution before expecting an assertion
- How to comment JSX code out in .js files in VSCode?
- How to download fetch response in react as file
- How to catch and handle error response 422 with Redux/Axios?
More Query from same tag
- How to get the value from URL params in React
- Issue with NPM start ( React)
- Backpressure implementation with redux-observable
- Iterating through keys of Immutable Map in React
- Creating package with customized component
- How can I find and click a button that has no text using React Testing Library?
- How to change the handleChange action based on the select input using react?
- conditional render not changing after state change
- React hooks pagination with useEffect - how to revert page number if request fails?
- React Recharts render blocking with a lot of data
- How can I do a jest test in this function in React axios?
- React.js (Reference Error: React is not defined)
- Property 'then' does not exist on type 'RelayObservable<unknown>'. when I try to fetch data using relay in react. I don't know why this error come
- TypeError: Cannot read property 'filter' of undefined (live searching)
- How to POST a JSON with data provided by user with REACTJS and Axios
- TypeScript type checking JSX children
- Should I inherit react props from HTMLProps<HTMLElement>?
- Redux - Is using getState not elegant or inefficient?
- React RC-Slider Grab vs Pointer on Label
- React on auto scroll on load more items
- TypeError: sha256_1.default is not a function
- Strange javascript toString() behaviour
- Make a rule that allows only those who are online from the database
- How to inject React Component inside WebView (react-native-webview)?
- How can I change the state of one React component based on the value of its sibling?
- React, cart with context and localstorage
- React TypeScript iterating over array full of objects using Array.prototype.map
- How to Start react application in production mode or in nginx server
- sorting array of objects and updating state
- Trying to switch between local and public webpage while looping through data