-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(webapp): harden RouteErrorDisplay against null error.data #4423
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
Closed
Ayush7614
wants to merge
1
commit into
triggerdotdev:main
from
Ayush7614:fix/route-error-display-null-data
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: fix | ||
| --- | ||
|
|
||
| Prevent dashboard error pages from crashing when a route error has no data payload |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { getRouteErrorMessage } from "./httpErrors"; | ||
|
|
||
| describe("getRouteErrorMessage", () => { | ||
| it("returns data.message when present", () => { | ||
| expect(getRouteErrorMessage(500, "Internal Server Error", { message: "boom" })).toBe("boom"); | ||
| }); | ||
|
|
||
| it("falls back when data is null", () => { | ||
| expect(getRouteErrorMessage(500, "Internal Server Error", null)).toBe( | ||
| "Something went wrong on our end. Please try again later." | ||
| ); | ||
| }); | ||
|
|
||
| it("falls back when data is undefined", () => { | ||
| expect(getRouteErrorMessage(404, "Not Found", undefined)).toBe( | ||
| "The page you're looking for doesn't exist." | ||
| ); | ||
| }); | ||
|
|
||
| it("uses a string data body", () => { | ||
| expect(getRouteErrorMessage(400, "Bad Request", "Invalid payload")).toBe("Invalid payload"); | ||
| }); | ||
|
|
||
| it("falls back when message is missing or empty", () => { | ||
| expect(getRouteErrorMessage(403, "Forbidden", {})).toBe( | ||
| "You don't have permission to access this resource." | ||
| ); | ||
| expect(getRouteErrorMessage(403, "Forbidden", { message: "" })).toBe( | ||
| "You don't have permission to access this resource." | ||
| ); | ||
| }); | ||
| }); | ||
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
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.
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.
🔴 New error-message tests fail because fallback returns the status text, not the generic message
The fallback message is built from the shared helper (
friendlyErrorDisplay(status, statusText).messageatapps/webapp/app/utils/httpErrors.ts:50), which returns the provided status text whenever one is given rather than the generic default the new tests expect, so the added test suite fails.Impact: The project's test run breaks, blocking the change from passing CI.
Mechanism: statusText short-circuits the default message
friendlyErrorDisplayreturnsstatusText ?? <default>for every case (apps/webapp/app/utils/httpErrors.ts:5-43). Every new test passes a truthystatusText(e.g."Internal Server Error","Not Found","Forbidden"), sofriendlyErrorDisplay(...).messageevaluates to that status text, never the generic default.Concretely:
getRouteErrorMessage(500, "Internal Server Error", null)returns"Internal Server Error", but the test atapps/webapp/app/utils/httpErrors.test.ts:10-12expects"Something went wrong on our end. Please try again later."getRouteErrorMessage(404, "Not Found", undefined)returns"Not Found", butapps/webapp/app/utils/httpErrors.test.ts:16-18expects"The page you're looking for doesn't exist."getRouteErrorMessage(403, "Forbidden", {})and(403, "Forbidden", { message: "" })return"Forbidden", butapps/webapp/app/utils/httpErrors.test.ts:26-31expects"You don't have permission to access this resource."Either the implementation must resolve the generic default when data is missing (e.g. call
friendlyErrorDisplay(status)withoutstatusText), or the test expectations must be corrected to the status-text values.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.