fix: Add HTTP status checking to fetch calls in JavaScript files#627
Merged
kesara merged 3 commits intoietf-tools:mainfrom Feb 17, 2026
Merged
fix: Add HTTP status checking to fetch calls in JavaScript files#627kesara merged 3 commits intoietf-tools:mainfrom
kesara merged 3 commits intoietf-tools:mainfrom
Conversation
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
Contributor
Author
|
Looking at test failures now |
Member
Thanks, I think those could be due to updates on |
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. |
kesara
reviewed
Feb 17, 2026
kesara
requested changes
Feb 17, 2026
Member
kesara
left a comment
There was a problem hiding this comment.
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.
kesara
approved these changes
Feb 17, 2026
Member
kesara
left a comment
There was a problem hiding this comment.
LGTM! Thanks for your contributions.
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
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:
render()(line 100) andvalidate()(line 167) functionscompare()function (line 227)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:
Users had to browse to their file again to recover it.
After: When
response.okis false, a clear error is thrown and caught: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: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):Testing
abnf.jsRelated Issues