feat(utils): introduce errors-as-values convention with tryCatchAsync helper [INTORG-713]#277
Open
Infi-Knight wants to merge 1 commit intostagingfrom
Open
feat(utils): introduce errors-as-values convention with tryCatchAsync helper [INTORG-713]#277Infi-Knight wants to merge 1 commit intostagingfrom
Infi-Knight wants to merge 1 commit intostagingfrom
Conversation
… helper [INTORG-713] The previous fetchStrapi quietly returned null on three different failure modes (missing Strapi config, non-ok response, exception). Callers couldn't tell "Strapi is down" from "page doesn't exist," and the type signature lied. This adds a tryCatchAsync helper in src/utils/shared/ (mirrored to cms/src/utils/ for later subs) that wraps throwing async work into a typed T | Error union. fetchStrapi now returns Promise<StrapiResponse<T> | Error>, so the type checker forces callers to narrow with instanceof Error before reaching the data field. The four SSR preview routes are updated to handle the Error case explicitly and declare the response shape they actually use (FoundationPagePreview, BlogPostPreview), removing the inline `as` cast that used to live in the foundation-page previews and dropping any reliance on `any`. Convention documented in CLAUDE.md under a new "Errors as Values" section. Foundation for the CMS-side subs INTORG-714, 715, 716.
✅ Deploy Preview for interledger-org-v5 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Summary
First sub-issue of INTORG-614. Adds a small
tryCatchAsynchelper, convertsfetchStrapito returnT | Error, and documents the convention in CLAUDE.md.The previous
fetchStrapiquietly returnednullon three different failure modes: missing Strapi config, non-ok response, exception inside the catch. Callers couldn't tell "Strapi is down" from "page doesn't exist," and the type signature lied. After this, callers narrow withinstanceof Errorbefore they can touchdata. The type checker enforces it.What's in the diff:
tryCatchAsync<T>(fn: () => T | Promise<T>): Promise<T | Error>helper insrc/utils/shared/tryCatch.tsandcms/src/utils/tryCatch.ts(mirrored so each side imports through its own utils barrel). Five vitest cases cover success, async rejection, sync throws, non-Error throw coercion, and a sync return.fetchStrapibecomes<T = unknown>(endpoint): Promise<StrapiResponse<T> | Error>.FoundationPagePreview,BlogPostPreview) and handle the Error case explicitly. Behaviour preserved: silent redirect to/404on the foundation routes, throw on the blog routes.Related Issue
INTORG-713 (parent: INTORG-614). Foundation for the CMS-side subs INTORG-714, 715, 716.
Manual Test
The four SSR preview routes:
Checks
pnpm run formatpnpm run lintPR Checklist
feat: ...,fix: ...)