Skip to content

fix(maticjs): surface the real cause of ABI/network metadata fetch failures - #477

Merged
MaximusHaximus merged 1 commit into
masterfrom
worktree-maticjs-error-visibility
Jun 26, 2026
Merged

MaximusHaximus merged 1 commit into
masterfrom
worktree-maticjs-error-visibility

Conversation

@MaximusHaximus

Copy link
Copy Markdown
Contributor

Problem

ABIManager.init() resolves network metadata by GETting <abiStoreUrl>/<network>/<version>/index.json. Two layers conspired to make any failure there undiagnosable:

  1. HttpRequest.get did a bare res.json() with no status check (src/utils/http_request.ts). A non-2xx response — e.g. a CDN/WAF 403/429, or an HTML error/challenge page served with a 200 — made res.json() throw a context-free Unexpected token <, losing the status entirely.
  2. Web3SideChainClient.init discarded that error (src/utils/web3_side_chain_client.ts): abiManager.init().catch(() => { throw new Error(\network ${network} - ${version} is not supported`) })`. The real cause was thrown away and replaced with a generic "not supported".

Net effect: a transport/CDN problem (throttling, edge error page, timeout, DNS) surfaces as network mainnet - v1 is not supported with no way to tell what actually went wrong. We hit this in downstream e2e CI — the manifest fetch fails intermittently from shared CI egress IPs, and the masked error gave us nothing to act on.

Fix

  • HttpRequest now checks res.ok and throws HTTP <status> <statusText> for <method> <url>: <body snippet> on a non-2xx, and on a 2xx-but-non-JSON body throws Expected JSON ... (content-type: ...) but parsing failed: <snippet>. Shared helper used by both get and post.
  • Web3SideChainClient.init preserves the underlying error — both inlined in the message (... is not supported: <reason>) and as the error's cause — instead of discarding it.

No behavioural change on the success path.

Tests

tests/http-request-error-visibility.test.ts (3 cases, local HTTP server): non-2xx surfaces status + body; non-JSON 2xx is reported with content-type + snippet; valid JSON still parses. Full package suite: 29 passed. Typecheck + webpack build green.

@MaximusHaximus
MaximusHaximus force-pushed the worktree-maticjs-error-visibility branch from c495b43 to 8631e39 Compare June 26, 2026 12:13
…ilures

ABIManager.init resolves network metadata over HTTP; the fetch did a bare
res.json() with no status check, and Web3SideChainClient.init then discarded
whatever it threw and rethrew a generic "network <x> - <v> is not supported".
Any transport/CDN problem (non-2xx, HTML error/challenge page, timeout) was
therefore undiagnosable.

HttpRequest now checks res.ok and reports the HTTP status + a body snippet
(and flags non-JSON bodies); init preserves the underlying error in the
message and as `cause`. Adds tests covering non-2xx, non-JSON-2xx, and the
happy path. No behavioural change on success.
@MaximusHaximus
MaximusHaximus force-pushed the worktree-maticjs-error-visibility branch from 8631e39 to 2dc5cc7 Compare June 26, 2026 12:17
@MaximusHaximus
MaximusHaximus marked this pull request as ready for review June 26, 2026 12:18
@claude

claude Bot commented Jun 26, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@MaximusHaximus
MaximusHaximus merged commit 554d0fc into master Jun 26, 2026
12 checks passed
@MaximusHaximus
MaximusHaximus deleted the worktree-maticjs-error-visibility branch June 26, 2026 12:29
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.

2 participants