-
-
Notifications
You must be signed in to change notification settings - Fork 713
Fix: UnhandledPromiseRejection crashing server when returning a 401 #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nst UnhandledRejection errors
|
WalkthroughThe changes made in this pull request focus on enhancing the asynchronous handling of API responses within the route builder functions. The Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint (1.23.1)
apps/webapp/app/services/routeBuilders/apiBuilder.server.ts(node:7971) ESLintIgnoreWarning: The ".eslintignore" file is no longer supported. Switch to using the "ignores" property in "eslint.config.js": https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files Oops! Something went wrong! :( ESLint: 9.15.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
apps/webapp/app/services/routeBuilders/apiBuilder.server.ts (1)
182-194
: Robust error handling, but consider reducing duplicationThe error handling is now properly handling async operations and providing good error logging. However, there's significant duplication of this logic across the three route builders.
Consider extracting the common error handling logic into a shared function:
async function handleRouteError( error: unknown, request: Request, corsStrategy: "all" | "none" ): Promise<Response> { try { if (error instanceof Response) { return await wrapResponse(request, error, corsStrategy !== "none"); } return await wrapResponse( request, json({ error: "Internal Server Error" }, { status: 500 }), corsStrategy !== "none" ); } catch (innerError) { logger.error("[apiBuilder] Failed to handle error", { error, innerError }); return json({ error: "Internal Server Error" }, { status: 500 }); } }Also applies to: 315-327, 529-541
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
(20 hunks)
🔇 Additional comments (2)
apps/webapp/app/services/routeBuilders/apiBuilder.server.ts (2)
549-558
: LGTM: Proper async/await handling for wrapResponse
The function is now correctly marked as async and properly awaits the apiCors call, which should resolve the UnhandledPromiseRejection issues.
81-84
: LGTM: Consistent async/await usage across all response wrapping
All calls to wrapResponse are now properly awaited, ensuring consistent handling of responses and preventing promise rejection issues.
Also applies to: 249-253, 402-406, 92-98, 260-266, 421-427, 109-115, 277-283, 438-444, 126-132, 294-300, 455-461, 471-474, 481-484, 490-493, 157-168, 511-514, 180-180, 313-313, 527-527
@trigger.dev/build
@trigger.dev/react-hooks
@trigger.dev/rsc
@trigger.dev/sdk
trigger.dev
@trigger.dev/core
commit: |
Summary by CodeRabbit