Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not found route should return a JSON response depending on the headers #50269

Closed
1 task done
eric-burel opened this issue May 24, 2023 · 0 comments
Closed
1 task done
Labels
Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx).

Comments

@eric-burel
Copy link
Contributor

eric-burel commented May 24, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #43~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Apr 21 16:51:08 UTC 2
    Binaries:
      Node: 18.10.0
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 7.17.1
    Relevant packages:
      next: 13.4.4-canary.7
      eslint-config-next: 13.4.3
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Data fetching (gS(S)P, getInitialProps), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/eric-burel/json-404

To Reproduce

git clone https://github.com/eric-burel/json-404
npm install
npm run dev

Open the home page and check the browser log (or the network devtools), they show the result of a client-side fetch call to an URL that do not exist.

Describe the Bug

When a route is not-found, the default response is a not-found HTML page.

This page can be configured via  not-found.js, however I couldn't figure how to change the response type to JSON, depending on the request "Accept" headers.

Expected Behavior

The content of the not found response should have the expected type depending on the request "Accept" header, here JSON.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@eric-burel eric-burel added the bug Issue was opened via the bug report template. label May 24, 2023
@github-actions github-actions bot added area: app Pages Router Related to Pages Router. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. labels May 24, 2023
@samcx samcx removed bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. area: app Pages Router Related to Pages Router. labels Jan 23, 2025
@samcx samcx added the Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx). label Mar 22, 2025
@vercel vercel locked and limited conversation to collaborators Mar 22, 2025
@samcx samcx converted this issue into discussion #77425 Mar 22, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx).
Projects
None yet
Development

No branches or pull requests

2 participants