Skip to content

fix(modules): clarify Run simulate API auth errors#1655

Draft
WGB5445 wants to merge 1 commit into
mainfrom
fix/run-simulate-401-error-message
Draft

fix(modules): clarify Run simulate API auth errors#1655
WGB5445 wants to merge 1 commit into
mainfrom
fix/run-simulate-401-error-message

Conversation

@WGB5445
Copy link
Copy Markdown
Contributor

@WGB5445 WGB5445 commented May 24, 2026

Context

On explorer.aptoslabs.com (mainnet), the account Modules → Run tab Simulate button can fail with HTTP 401 from the Aptos fullnode:

POST https://api.mainnet.aptoslabs.com/v1/transactions/simulate
Unauthorized: Rejected due to a per-IP blocking rule for this application

This is an API Gateway authentication / per-IP policy response—not a Move VM simulation failure.

Why Write can still work: Simulate uses Explorer’s browser sdkV2Client (getApiKey()Authorization: Bearer … on api.mainnet.aptoslabs.com). Write uses the connected wallet’s signAndSubmitTransaction and the wallet’s own mainnet RPC, so wallet submit can succeed while Simulate fails.

Common causes: invalid Settings → API Keys mainnet override (replaces the built-in key), missing Authorization on the simulate request, or gateway per-IP rules for the application client ID.

Covers FEAT-MODULES-001 (Run sub-tab).

What changed

  • Add formatAptosApiErrorForDisplay() (app/utils/aptosApiErrorMessage.ts) to detect HTTP 401 / 429 (and related gateway copy) and return user-facing text that distinguishes API access failures from Move execution errors.
  • Run tab (Contract.tsx): on simulate failure, show the friendly message and, when appropriate, a link to Settings → API keys.
  • Unit tests for the 401 per-IP blocking message shape reported in production.

Links

Fixes #1654
Fixes DVR-161

Test plan

  • pnpm test --run app/utils/aptosApiErrorMessage.test.ts
  • pnpm lint
  • Manual: Modules → Run → Simulate with invalid Settings mainnet API key → friendly message + Settings link
  • Manual: valid key / default prod key → simulate still works for a simple entry function

When Simulate hits Aptos API gateway 401/429 responses, show actionable
copy and link to Settings instead of raw SDK error text.

Fixes #1654

Co-authored-by: Cursor <cursoragent@cursor.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 24, 2026

Deploy Preview for aptos-explorer ready!

Name Link
🔨 Latest commit 1a0dbc4
🔍 Latest deploy log https://app.netlify.com/projects/aptos-explorer/deploys/6a12dc857f93420008a154e1
😎 Deploy Preview https://deploy-preview-1655--aptos-explorer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 32 (🔴 down 21 from production)
Accessibility: 98 (no change from production)
Best Practices: 83 (🔴 down 9 from production)
SEO: 92 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Bundle Report

Changes will increase total bundle size by 2.87kB (0.03%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
aptos-explorer-client-esm 6.16MB 1.05kB (0.02%) ⬆️
aptos-explorer-server-esm 1.98MB 1.82kB (0.09%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: aptos-explorer-server-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/Index-*.js 1.82kB 238.39kB 0.77%

Files in assets/Index-*.js:

  • ./app/pages/Account/Tabs/ModulesTab/Contract.tsx → Total Size: 46.05kB

  • ./app/utils/aptosApiErrorMessage.ts → Total Size: 1.32kB

view changes for bundle: aptos-explorer-client-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/Index-*.js 1.05kB 165.02kB 0.64%

Files in assets/Index-*.js:

  • ./app/utils/aptosApiErrorMessage.ts → Total Size: 1.16kB

  • ./app/pages/Account/Tabs/ModulesTab/Contract.tsx → Total Size: 50.67kB

@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.08%. Comparing base (12ade38) to head (1a0dbc4).

Files with missing lines Patch % Lines
app/utils/aptosApiErrorMessage.ts 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1655      +/-   ##
==========================================
+ Coverage   31.97%   32.08%   +0.11%     
==========================================
  Files         182      183       +1     
  Lines        8561     8579      +18     
  Branches     3215     3226      +11     
==========================================
+ Hits         2737     2753      +16     
- Misses       5820     5822       +2     
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +1067 to +1079
{simulationError.suggestSettings && (
<Typography
variant="body2"
sx={{
color: "text.secondary",
mt: 1,
}}
>
Check <Link to="/settings">API keys in Settings</Link>.
An invalid or expired mainnet override replaces the
built-in key used for simulation.
</Typography>
)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only makes sense if the API key is overridden, maybe we should check that state?

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.

Run tab Simulate returns 401 per-IP blocking on mainnet (wallet submit still works)

2 participants