forwardemail / forwardemail/superagent

[fix] Can't handle socket hangup (pipe)

Open
#1,772 1 comment 0 reactions 0 assignees View on GitHub
Bug
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug

**Node.js version:** v18.17.0

**OS version:** Windows (but confirmed on MacOS as well)

**Description:**

Hi there,

I dont see any way of handling socket errors after initial connection has been established. I'm trying to download a large file with superagent and during download sometimes something happens and connection is broken. I tried to catch that error but it doesn't seem that superagent is notifing about those errors at all.

See code sample:

```typescript
public static downloadFileToStream(url: string, stream: WriteStream) {
return new Promise((resolve, reject) => {
superagent.get(url)
.on('error', (e) => {
logger.error('Req Error!', e);
reject(e);
})
.pipe(stream)
.on('error', (e) => {
logger.trace('Error!', e);
reject(e);
})
.on('close', () => {
logger.trace('File downloaded!');
resolve({});
})
});
}
```

## Actual behavior

If error occurs during connection establishing, is see proper `Req Error` log messages, but after that, if error occurs during actual data transfer, I dont see anything.

## Expected behavior

I would expect to get error event, when error occurs during data transfer.
Afaik this problem may be just related to stream operation (pipe), I havent verified that without using streams

## Checklist

- [x] I have searched through GitHub issues for similar issues.
- [x] I have completely read through the README and documentation.
- [x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.