Uncatchable error is thrown when a HTTPS post request fails
See original GitHub issueBug Description
When making an HTTPS post request to a URL that doesn’t respond/exist, an AssertionError is thrown that cannot be caught by the consumer.
Reproducible By
Wrap a post request to an unreachable URL in a try…catch Observe how the script is terminated without the error being caught
Code example:
import {request} from 'undici'
try {
await request("https://thisis.not/avalid/url", {method: "POST");
} catch {
console.log("Error caught, this never happens");
}
Expected Behavior
The promise should be rejected so that the error can be caught and handled by the consumer
Logs
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(this.servername)
at TLSSocket.<anonymous> (C:\path\node_modules\undici\lib\core\connect.js:61:11)
at TLSSocket.emit (node:events:377:35)
at emitErrorNT (node:internal/streams/destroy:193:8)
at emitErrorCloseNT (node:internal/streams/destroy:158:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: null,
expected: true,
operator: '=='
}
Environment
Windows 10, Node v16.2.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Do uncatchable exceptions exist in Javascript? - Stack Overflow
I guess the errors thrown in a separate execution context are catchable or not depending on whether you're willing to modify someone else's...
Read more >Can't catch error using callback and on-error handler #2161
I'm writing an application that needs to be robust with respect to handling failed connections. Is this a bug, or am I doing...
Read more >Handling errors - Node-RED
These are uncatchable errors. If it does notify the runtime properly, then it is a catchable error that can be used to trigger...
Read more >412 Precondition Failed - HTTP - MDN Web Docs - Mozilla
If the hashes don't match, it means that the document has been edited in-between and a 412 Precondition Failed error is thrown.
Read more >Fetch - Error Handling for Failed HTTP Responses and ...
A quick example of how to handle both network errors and HTTP errors (4xx or 5xx) for fetch requests in a single catch...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey guys! If still up to, I would love to try this fix 🙏
Merged fix