Skip to content

Commit 224f65f

Browse files
committed
refactor code to coderabbit's suggestions
1 parent e5ee13d commit 224f65f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/server/src/next/app-route-handler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { AppRouteRequestHandlerOptions } from '.';
66
import { RPCApiHandler } from '../api';
77
import { loadAssets } from '../shared';
88

9-
type Context = { params: Promise<{ path: string[] }> };
9+
type Context = { params: Promise<{ path: string[] }> | { path: string[] } };
1010

1111
/**
1212
* Creates a Next.js 13 "app dir" API route request handler which encapsulates Prisma CRUD operations.
1313
*
14+
* @remarks Since Next.js 15, `context.params` is asynchronous and must be awaited.
1415
* @param options Options for initialization
1516
* @returns An API route request handler
1617
*/
@@ -27,10 +28,16 @@ export default function factory(
2728
return NextResponse.json({ message: 'unable to get prisma from request context' }, { status: 500 });
2829
}
2930

31+
let params: Context['params'];
3032
const url = new URL(req.url);
31-
const params = await context.params;
3233
const query = Object.fromEntries(url.searchParams);
3334

35+
try {
36+
params = await context.params;
37+
} catch {
38+
return NextResponse.json({ message: 'Failed to resolve request parameters' }, { status: 500 });
39+
}
40+
3441
if (!params.path) {
3542
return NextResponse.json(
3643
{ message: 'missing path parameter' },

0 commit comments

Comments
 (0)