Unverified Commit b4080311 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[Breaking] Rename instrumentation onRequestError `context.routeType` from…

[Breaking] Rename instrumentation onRequestError `context.routeType` from `middleware` to `proxy` (#85006)

Follow up on https://github.com/vercel/next.js/pull/84710,
`instrumentation` docs had `onRequestError` function's param
`context.routeType` has value of `'middleware'`. As it's a user-facing
value, update it to `'proxy'`.
parent bbfcbe96
...@@ -93,7 +93,7 @@ export function onRequestError( ...@@ -93,7 +93,7 @@ export function onRequestError(
context: { context: {
routerKind: 'Pages Router' | 'App Router' // the router type routerKind: 'Pages Router' | 'App Router' // the router type
routePath: string // the route file path, e.g. /app/blog/[dynamic] routePath: string // the route file path, e.g. /app/blog/[dynamic]
routeType: 'render' | 'route' | 'action' | 'middleware' // the context in which the error occurred routeType: 'render' | 'route' | 'action' | 'proxy' // the context in which the error occurred
renderSource: renderSource:
| 'react-server-components' | 'react-server-components'
| 'react-server-components-payload' | 'react-server-components-payload'
...@@ -106,7 +106,7 @@ export function onRequestError( ...@@ -106,7 +106,7 @@ export function onRequestError(
- `error`: The caught error itself (type is always `Error`), and a `digest` property which is the unique ID of the error. - `error`: The caught error itself (type is always `Error`), and a `digest` property which is the unique ID of the error.
- `request`: Read-only request information associated with the error. - `request`: Read-only request information associated with the error.
- `context`: The context in which the error occurred. This can be the type of router (App or Pages Router), and/or (Server Components (`'render'`), Route Handlers (`'route'`), Server Actions (`'action'`), or Middleware (`'middleware'`)). - `context`: The context in which the error occurred. This can be the type of router (App or Pages Router), and/or (Server Components (`'render'`), Route Handlers (`'route'`), Server Actions (`'action'`), or Proxy (`'proxy'`)).
### Specifying the runtime ### Specifying the runtime
......
...@@ -24,18 +24,18 @@ if (typeof handler !== 'function') { ...@@ -24,18 +24,18 @@ if (typeof handler !== 'function') {
) )
} }
// Middleware will only sent out the FetchEvent to next server, // Proxy will only sent out the FetchEvent to next server,
// so load instrumentation module here and track the error inside middleware module. // so load instrumentation module here and track the error inside proxy module.
function errorHandledHandler(fn: AdapterOptions['handler']) { function errorHandledHandler(fn: AdapterOptions['handler']) {
return async (...args: Parameters<AdapterOptions['handler']>) => { return async (...args: Parameters<AdapterOptions['handler']>) => {
try { try {
return await fn(...args) return await fn(...args)
} catch (err) { } catch (err) {
// In development, error the navigation API usage in runtime, // In development, error the navigation API usage in runtime,
// since it's not allowed to be used in middleware as it's outside of react component tree. // since it's not allowed to be used in proxy as it's outside of react component tree.
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
if (isNextRouterError(err)) { if (isNextRouterError(err)) {
err.message = `Next.js navigation API is not allowed to be used in Middleware.` err.message = `Next.js navigation API is not allowed to be used in ${isProxy ? 'Proxy' : 'Middleware'}.`
throw err throw err
} }
} }
...@@ -51,8 +51,8 @@ function errorHandledHandler(fn: AdapterOptions['handler']) { ...@@ -51,8 +51,8 @@ function errorHandledHandler(fn: AdapterOptions['handler']) {
}, },
{ {
routerKind: 'Pages Router', routerKind: 'Pages Router',
routePath: '/middleware', routePath: '/proxy',
routeType: 'middleware', routeType: 'proxy',
revalidateReason: undefined, revalidateReason: undefined,
} }
) )
......
export type RequestErrorContext = { export type RequestErrorContext = {
routerKind: 'Pages Router' | 'App Router' routerKind: 'Pages Router' | 'App Router'
routePath: string // the route file path, e.g. /app/blog/[dynamic] routePath: string // the route file path, e.g. /app/blog/[dynamic]
routeType: 'render' | 'route' | 'action' | 'middleware' routeType: 'render' | 'route' | 'action' | 'proxy'
renderSource?: renderSource?:
| 'react-server-components' | 'react-server-components'
| 'react-server-components-payload' | 'react-server-components-payload'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment