-
-
Notifications
You must be signed in to change notification settings - Fork 972
Closed
Labels
bugSomething does not work as it shouldSomething does not work as it shouldexternalThe issue related to an external projectThe issue related to an external project
Description
How do I prevent my app from crashing when posting a stream to an offline destination? In both examples below I get:
internal/streams/legacy.js:59
throw er; // Unhandled stream error in pipe.
^
Error: connect ECONNREFUSED 127.0.0.1:2024
at TCPConnectWrap.afterConnect
(I'm on node v12.1.0)
import FormData from 'form-data';
import got from 'got';
import fs from 'fs';
(async () => {
try {
const form = new FormData();
form.append('upload', fs.createReadStream('filepath.jpg'));
await got.post('http://offlinesite123.com', {
body: form,
});
} catch (err) {
console.error('does not catch', err);
}
})();this also crashes my app
try {
const form = new FormData();
form.append('upload', fs.createReadStream('filepath.jpg'));
got.stream
.post('http://offlinesite123.com', {
body: form,
})
.on('error', err => console.error('this error gets reported but app still crashes'));
} catch (err) {
console.error('does not catch', err);
}Checklist
- I have read the documentation.
Metadata
Metadata
Assignees
Labels
bugSomething does not work as it shouldSomething does not work as it shouldexternalThe issue related to an external projectThe issue related to an external project