Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| @@ -8,7 +8,7 @@ import {DeRefedOpenAPI} from './open-api/types'; | |||
|
|
|||
| // SENTRY_API_SCHEMA_SHA is used in the sentry-docs GHA workflow in getsentry/sentry-api-schema. | |||
There was a problem hiding this comment.
Bug: The resolveOpenAPI function doesn't check if the HTTP response is successful before parsing it as JSON, which can cause cryptic build failures.
Severity: HIGH
Suggested Fix
Before calling await response.json(), add a check for the HTTP response status. If !response.ok, throw a new error with a more informative message, including the status and status text, to clarify why the fetch failed. This will prevent cryptic JSON parsing errors and make debugging build failures easier. Example: if (!response.ok) { throw new Error(Failed to fetch OpenAPI schema: ${response.status} ${response.statusText}); }.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/build/resolveOpenAPI.ts#L9
Potential issue: The `resolveOpenAPI` function fetches an OpenAPI schema from a
`raw.githubusercontent.com` URL. It directly calls `response.json()` without first
verifying `response.ok`. If the requested file is unavailable (e.g., due to an invalid
commit SHA), GitHub will return a 404 response with an HTML body. The `fetch` API does
not treat this as an error, so the code proceeds to call `response.json()` on the HTML,
which throws a cryptic `SyntaxError`. Since this function is called during the build
process (`generateStaticParams`), this error will cause the entire site build to fail,
preventing deployment.
Did we get this right? 👍 / 👎 to inform future reviews.
No description provided.