I’m not sure how many scenarios this issue would crop up in, but I wanted to at least post about the one that I found:
1 |
{ [Error: socket hang up] code: 'ECONNRESET'} |
This happens on my iojs/express api that I’m working on, and trying to do a file upload test with mocha and supertest.
If you are doing something like this:
1 2 3 4 5 |
request(app) .post('/upload') .attach('file', 'fixtures/photo.jpg') .send({'key':'value'}) .end(function(){...}); |
.attach() is not compatible with .send().
You need to remove .send() and put that data into .field() function calls like this:
1 2 3 4 5 |
.post('/upload') .field('user_id', 1) .field('detail', {...}) .attach('file', __dirname + '/fixtures/photo.jpg') .end(...) |
Doing this completely resolved theĀ { [Error: socket hang up] code: ‘ECONNRESET’} error that I was receiving.
Hope this helps anyone with the same issue.