Skip to content

Commit 8f4969f

Browse files
committed
make handler type version agnostic
1 parent ff4f97f commit 8f4969f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/nextjs/src/utils/withSentry.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ import {
1010
stripUrlQueryAndFragment,
1111
} from '@sentry/utils';
1212
import * as domain from 'domain';
13-
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
14-
15-
// This is the same as the `NextApiHandler` type, except instead of having a return type of `void | Promise<void>`, it's
16-
// only `Promise<void>`, because wrapped handlers are always async
17-
export type WrappedNextApiHandler = (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
13+
import { NextApiRequest, NextApiResponse } from 'next';
14+
15+
// These are the same as the official `NextApiHandler` type, except
16+
//
17+
// a) Instead of having a return type of `void | Promise<void>` (Next < 12.1.6) or `unknown | Promise<unknown>` (Next
18+
// 12.1.6+), the unwrapped version has both.
19+
//
20+
// b) The wrapped version returns only promises, because wrapped handlers are always async.
21+
//
22+
// TODO: Fix the need for the multi-version hack. See XXXXXX.
23+
export type NextApiHandler = (
24+
req: NextApiRequest,
25+
res: NextApiResponse,
26+
) => void | Promise<void> | unknown | Promise<unknown>;
27+
export type WrappedNextApiHandler = (req: NextApiRequest, res: NextApiResponse) => Promise<void> | Promise<unknown>;
1828

1929
export type AugmentedNextApiResponse = NextApiResponse & {
2030
__sentryTransaction?: Transaction;

0 commit comments

Comments
 (0)