Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build/resolveOpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// DO NOT change variable name unless you change it in the sentry-docs GHA workflow in getsentry/sentry-api-schema.
const SENTRY_API_SCHEMA_SHA = 'd01587d742c372e25782eaa7e78e6df8286bfbc9';
const SENTRY_API_SCHEMA_SHA = 'dcb185faee28389a8eeeab4d09d1b9e0f7997963';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The fetch call in resolveOpenAPI lacks error handling. It calls response.json() without first checking if the network request was successful via response.ok, which can cause crashes.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The resolveOpenAPI function fetches a JSON schema from GitHub using fetch. However, it does not check if the response was successful (e.g., response.ok) before attempting to parse the body as JSON with response.json(). If GitHub returns a non-2xx status code, such as a 404 or 500, response.json() will fail when trying to parse the resulting error page's HTML. This unhandled promise rejection will cause a Next.js server component to crash, resulting in a 500 error for the user, or cause the entire site build to fail during the mdx.ts execution.

💡 Suggested Fix

Before calling await response.json(), add a check to ensure the request was successful. For example: if (!response.ok) { throw new Error(Failed to fetch API schema: ${response.statusText}); }. This will provide a clear error message and prevent crashes from attempting to parse non-JSON responses.

🤖 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#L12

Potential issue: The `resolveOpenAPI` function fetches a JSON schema from GitHub using
`fetch`. However, it does not check if the response was successful (e.g., `response.ok`)
before attempting to parse the body as JSON with `response.json()`. If GitHub returns a
non-2xx status code, such as a 404 or 500, `response.json()` will fail when trying to
parse the resulting error page's HTML. This unhandled promise rejection will cause a
Next.js server component to crash, resulting in a 500 error for the user, or cause the
entire site build to fail during the `mdx.ts` execution.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7465370

const activeEnv = process.env.GATSBY_ENV || process.env.NODE_ENV || 'development';

Expand Down
Loading