Skip to content

fix: add HTTP response status validation to fetch() calls - #1391

Open
Raushankumar0720 wants to merge 2 commits into
asyncapi:masterfrom
Raushankumar0720:fix/add-http-response-validation
Open

Raushankumar0720 wants to merge 2 commits into
asyncapi:masterfrom
Raushankumar0720:fix/add-http-response-validation

Conversation

@Raushankumar0720

@Raushankumar0720 Raushankumar0720 commented Oct 1, 2026 •

Copy link
Copy Markdown

Description

Multiple fetch() calls across studio services lacked response.ok status validation before reading the response body. Because fetch() does not reject on HTTP error status codes (such as 404 Not Found or 500 Internal Server Error), failed network requests were silently passed into YAML/JSON parsers as HTML error pages, resulting in confusing syntax errors.

This PR adds explicit HTTP response validation across:

  • EditorService.switchToFile() and EditorService.importFromURL()
  • ApplicationService.fetchResource()
  • ParserService.createRemoteTrackingResolver()

Behavior Comparison

Scenario Previous Behavior Fixed Behavior
HTTP 404 / 500 on URL Import Passes raw HTML error page to parser, throwing SyntaxError: Unexpected token '<' Throws descriptive error: Failed to fetch from URL (HTTP 404: Not Found)
HTTP 401 / 403 on Remote Spec Silent parse failure or unhandled state Propagates clean HTTP error message to the UI
HTTP 200 (Success) Unchanged Unchanged

Test Verification

Added unit tests in apps/studio/src/services/tests/editor-http-validation.test.ts verifying error handling for 200, 404, and 500 status codes:

PASS apps/studio/src/services/tests/editor-http-validation.test.ts
  EditorService HTTP Validation
    ✓ should successfully return content on HTTP 200 OK (14 ms)
    ✓ should throw descriptive error on HTTP 404 Not Found (8 ms)
    ✓ should throw descriptive error on HTTP 500 Server Error (6 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total

Related issue(s)

Resolves #1390

Multiple fetch() calls across the codebase did not check response.ok
before processing the response body. Since the JavaScript fetch() API
does not throw on HTTP error statuses (e.g. 404, 500), the application
silently loaded error pages as if they were valid AsyncAPI documents,
causing confusing parser errors.

This commit adds response.ok checks to all 4 affected fetch() calls:

- editor.service.tsx: switchToFile() and importFromURL()
- app.service.ts: fetchResource()
- parser.service.ts: createRemoteTrackingResolver()

Closes asyncapi#1390
@changeset-bot

changeset-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aa49fef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/studio Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for asyncapi-studio-design-system ready!

Name Link
🔨 Latest commit aa49fef
🔍 Latest deploy log https://app.netlify.com/projects/asyncapi-studio-design-system/deploys/6abe9c44c1399100087bcf7d
😎 Deploy Preview https://deploy-preview-1391--asyncapi-studio-design-system.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for modest-rosalind-098b67 ready!

Name Link
🔨 Latest commit aa49fef
🔍 Latest deploy log https://app.netlify.com/projects/modest-rosalind-098b67/deploys/6abe9c44135a0700097df44c
😎 Deploy Preview https://deploy-preview-1391--modest-rosalind-098b67.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

@Raushankumar0720

Copy link
Copy Markdown
Author

@Amzani @KhudaDad414

Hi maintainers!
All automated CI checks, unit tests, and DCO sign-offs are passing green. Whenever you have a moment, could you please take a look and share your review?

Thank you so much for your time and guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

bug: missing HTTP response status validation in fetch() calls causes confusing errors on failed URL imports

1 participant