Does anybody works with koa.js and streams?
Consider this example
const fs = require('fs');
const Koa = require('koa');
const app = new Koa();
app.use(async (ctx) => {
ctx.body = fs.createReadStream('really-large-file');
});
app.listen(4000);
If user aborts request I'm getting either
Error: read ECONNRESET
at _errnoException (util.js:1024:11)
at TCP.onread (net.js:618:25)
or
Error: write EPIPE
at _errnoException (util.js:1024:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:870:14)
What is the proper way to handle this type of errors?
P.S. I have no errors after request aborts with express
const fs = require('fs');
const express = require('express');
const app = express();
app.get('/', (req, res) => {
fs.createReadStream('really-large-file').pipe(res);
});
app.listen(4000);
P.P.S. I've tried
app.use(async (ctx) => {
fs.createReadStream('really-large-file').pipe(ctx.res);
ctx.respond = false;
});
But it had no effect.