Skip to content

Improve fetch TLS certificate error messages#5326

Closed
Will-thom wants to merge 1 commit into
nodejs:mainfrom
Will-thom:oss/undici-tls-fetch-error
Closed

Improve fetch TLS certificate error messages#5326
Will-thom wants to merge 1 commit into
nodejs:mainfrom
Will-thom:oss/undici-tls-fetch-error

Conversation

@Will-thom
Copy link
Copy Markdown
Contributor

Fixes #2199.

This keeps the fetch TypeError shape and cause intact while surfacing TLS certificate verification details in the top-level error message for known certificate-related failures.

Tests:

  • node --test test\fetch\tls-certificate-error.js
  • node --test test\fetch\client-error-stack-trace.js
  • borp focused test/fetch/tls-certificate-error.js
  • borp focused test/fetch/client-error-stack-trace.js
  • eslint lib/web/fetch/index.js test/fetch/tls-certificate-error.js

Note: npm run build:node could not be executed in this Windows sandbox because npm/esbuild attempted to access a denied path outside the workspace before compiling.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (f049730) to head (c927df4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5326      +/-   ##
==========================================
+ Coverage   93.21%   93.22%   +0.01%     
==========================================
  Files         110      110              
  Lines       36598    36615      +17     
==========================================
+ Hits        34115    34136      +21     
+ Misses       2483     2479       -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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

I think this is spec mandated. @KhafraDev

Copy link
Copy Markdown
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

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

It's not spec mandated (other than having to throw a TypeError), but there are a number of libraries that check for the error message 'fetch failed', which this change would break. is-network-error is one of the largest ones.

@KhafraDev KhafraDev closed this May 27, 2026
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.

Unprecise error message on fetch() to an endpoint with a certificate which was signed by an "unkown" CA

4 participants