Skip to content

fix: Add HTTP status checking to fetch calls in JavaScript files#627

Merged
kesara merged 3 commits intoietf-tools:mainfrom
1456055067:fix/http-status-checking
Feb 17, 2026
Merged

fix: Add HTTP status checking to fetch calls in JavaScript files#627
kesara merged 3 commits intoietf-tools:mainfrom
1456055067:fix/http-status-checking

Conversation

@1456055067
Copy link
Contributor

@1456055067 1456055067 commented Feb 16, 2026

Summary

Users previously faced cryptic errors, such as unexpected JSON parse failures, when a server request failed. Now, response.ok checks have been added to all fetch calls before processing responses. This prevents confusing errors when the server returns non-200 HTTP status codes.

Changes

Modified four fetch handlers to check HTTP status before processing responses:

  • main.js: Added status checks to render() (line 100) and validate() (line 167) functions
  • iddiff.js: Added status check to compare() function (line 227)
  • rfcdiff.js: Added status check to compare() function (line 214)

Problems Fixed

Issue #603 - JSON parse errors on conversion failure

Before: When the XML2RFC conversion failed, the JavaScript tried to parse error responses as JSON, causing:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Users had to browse to their file again to recover it.

After: When response.ok is false, a clear error is thrown and caught:

There was an issue processing your request. (HTTP Status: 500)

Issue #506 - TypeError on large file uploads

Before: When users uploaded files larger than 5MB, the server returned an HTTP 413 (Payload Too Large) error. The code tried to extract a <table> element from the error response, causing:

TypeError: Node.appendChild: Argument 1 is not an object

After: The HTTP 413 status is detected, and a clear error message is shown to the user.

Implementation

All changes follow the same pattern already successfully implemented in abnf.js (commit 5374514, PR #573):

fetch(request)
    .then(function(response) {
    if (!response.ok) {
      throw new Error(`There was an issue processing your request. (HTTP Status: ${response.status})`);
    }
    return response.json(); // or response.blob()
  })

Testing

  • Verified that all fetch handlers now have consistent error checks
  • Changes match the working pattern in abnf.js
  • Error messages include HTTP status codes for debugging.

Related Issues

Add response.ok checks before processing fetch responses to prevent
errors when server returns non-200 status codes. This fixes issues
where:
- JSON parsing fails on error responses (HTTP 4xx/5xx)
- Large file uploads (>5MB) return HTTP 413 causing TypeError
- Users must re-browse files after conversion failures

Changes:
- main.js: Add status check to render() and validate() functions
- iddiff.js: Add status check to compare() function
- rfcdiff.js: Add status check to compare() function

All changes follow the same pattern already implemented in abnf.js
(PR ietf-tools#573).

When response.ok is false, the code now throws a clear error message
with the HTTP status code, which is caught and displayed to the user
instead of causing confusing JavaScript errors.

Fixes ietf-tools#603, Fixes ietf-tools#506
@1456055067
Copy link
Contributor Author

Looking at test failures now

@kesara
Copy link
Member

kesara commented Feb 17, 2026

Looking at test failures now

Thanks, I think those could be due to updates on html-validate. Tests doesn't pin a certain version, uses the latest available.

@1456055067
Copy link
Contributor Author

Fixed the HTML validation due to aria-labelledby failure. ended up having to switch the div to a section. div doesn't support aria-labelledby.

Copy link
Member

@kesara kesara left a comment

Choose a reason for hiding this comment

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

Because API returns non-200 HTTP status codes with error information, the proposed changes will stop displaying those errors.

Only throw for non-OK responses that aren't JSON. The API returns
400 with JSON error details that should still be parsed and displayed
by the existing error handling code. Infrastructure errors (413, 502)
return HTML and should be caught early with a clear status message.
Copy link
Member

@kesara kesara left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your contributions.

@kesara kesara merged commit 6290d5d into ietf-tools:main Feb 17, 2026
2 checks passed
@1456055067 1456055067 deleted the fix/http-status-checking branch February 17, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Author's Tool website requires re-browse on xml2rfc conversion failure TypeError: Node.appendChild: Argument 1 is not an object.

2 participants