-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DX: add route context to dynamic errors for app routes (#62844)
Gives the users pathname context on routes that access Dynamic API's so that if these errors are caught they can modify their code accordingly. This is a followup to #61332. Closes NEXT-2695
- Loading branch information
Showing
6 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/dynamic-data/fixtures/main/app/routes/next-url/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const GET = async (request) => { | ||
try { | ||
const body = JSON.stringify({ pathname: request.nextUrl.toString() }) | ||
return new Response(body, { | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}) | ||
} catch (err) { | ||
console.log('Caught Error:', err.message) | ||
return new Response(null, { status: 500 }) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/dynamic-data/fixtures/main/app/routes/url/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const GET = async (request) => { | ||
try { | ||
const body = JSON.stringify({ url: request.url }) | ||
return new Response(body, { | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}) | ||
} catch (err) { | ||
console.log('Caught Error:', err.message) | ||
return new Response(null, { status: 500 }) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/dynamic-data/fixtures/require-static/app/routes/form-data/error/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const dynamic = 'error' | ||
|
||
export const GET = async (request) => { | ||
return new Response( | ||
JSON.stringify({ query: request.formData.get('query') }), | ||
{ | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
} | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/dynamic-data/fixtures/require-static/app/routes/next-url/error/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const dynamic = 'error' | ||
|
||
export const GET = async (request) => { | ||
return new Response( | ||
JSON.stringify({ pathname: request.nextUrl.toString() }), | ||
{ | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
} | ||
) | ||
} |