chore: write defaultResponder for App Router APIs#19727
Merged
sean-brydon merged 5 commits intomainfrom Mar 5, 2025
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
defaultResponder for App Router APIs
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (03/04/25)1 reviewer was added to this PR based on Keith Williams's automation. |
hbjORbj
commented
Mar 4, 2025
Comment on lines
-8
to
-36
| export const apiRouteMiddleware = | ||
| (handler: (req: NextRequest, { params }: { params: Params }) => Promise<NextResponse | Response>) => | ||
| async (req: NextRequest, { params }: { params: Params }) => { | ||
| try { | ||
| return await handler(req, { params }); | ||
| } catch (error) { | ||
| if (error instanceof ApiError) { | ||
| return NextResponse.json({ message: error.message }, { status: error.statusCode }); | ||
| } else { | ||
| const serverError = getServerErrorFromUnknown(error); | ||
| // we don't want to report Bad Request errors to Sentry / console | ||
| if (!(serverError.statusCode >= 400 && serverError.statusCode < 500)) { | ||
| console.error(error); | ||
| const captureException = (await import("@sentry/nextjs")).captureException; | ||
| captureException(error); | ||
| } | ||
| return NextResponse.json( | ||
| { | ||
| message: serverError.message, | ||
| url: serverError.url, | ||
| method: serverError.method, | ||
| }, | ||
| { | ||
| status: serverError.statusCode, | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| }; |
Contributor
Author
There was a problem hiding this comment.
This util had some parts of defaultResponder code but it's still missing a lot of it. I removed this entirely and rewrote a new wrapper called defaultResponderForAppDir
hbjORbj
commented
Mar 4, 2025
Comment on lines
-118
to
-120
| const getHandler = apiRouteMiddleware(handler); | ||
|
|
||
| export { getHandler as GET }; |
Contributor
Author
There was a problem hiding this comment.
- We run this API (/social/og/image) on Edge, and
import { performance } from "@calcom/lib/server/perfObserver";indefaultResponderForAppDircan only run in Node.js. - Ideally, we should modify this performance function, so that we can use the wrapper in APIs running on Edge too
- But it is not high priority, because in Pages Router, we weren't using
defaultResponderfor this API anyways
Contributor
E2E results are ready! |
sean-brydon
approved these changes
Mar 5, 2025
Member
sean-brydon
left a comment
There was a problem hiding this comment.
LGTM - will merge and implement in our other api PRs
itsalam
pushed a commit
to itsalam/cal.com
that referenced
this pull request
Mar 6, 2025
* create defaultResponderForAppDir * rename all usages * finish * fix
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?