question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaxFileSizeUploadError can't be caught and crashes the server

See original GitHub issue

Hi!

I have a problem with a custom middleware and the use of the processRequest function. Here is my custom middleware:

try {
    return processRequest(request, options)
                    .then(body => {
                        console.log("body is : ", body);
                        ctx.request.body = body;
                        return next();
                    })
                    .catch(error => {
                        console.log("Error catched : ", error);
                        if (error.status && error.expose) response.status(error.status);
                        return next(error)
                    });
} catch (error) {
    console.log("Error catched bis : ", error);
}

If I try to upload a file bigger than the allowed limit, I get the following error and my app crash.

events.js:137
      throw er; // Unhandled 'error' event
      ^

MaxFileSizeUploadError: File truncated as it exceeds the size limit.
    at FileStream.file.stream.once (/Volumes/lake/projects/evibe/api-lovejs/node_modules/apollo-upload-server/lib/middleware.js:35:13)
    at Object.onceWrapper (events.js:255:19)
    at FileStream.emit (events.js:160:13)

I can’t capture the error. Any idea?

Thanks 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
Luchansocommented, Nov 15, 2021

I have the same problem, in my case file stream throw error and not exist handlers for that error.

node-backend            |   PayloadTooLargeError: File truncated as it exceeds the 3145728 byte size limit.
node-backend            |       at FileStream.<anonymous> (/app/node_modules/graphql-upload/public/processRequest.js:289:21)
node-backend            |       at FileStream.emit (node:events:390:28)
node-backend            |       at PartStream.onData (/app/node_modules/busboy/lib/types/multipart.js:221:18)
node-backend            |       at PartStream.emit (node:events:390:28)
node-backend            |       at addChunk (node:internal/streams/readable:315:12)
node-backend            |       at readableAddChunk (node:internal/streams/readable:289:9)
node-backend            |       at PartStream.Readable.push (node:internal/streams/readable:228:10)
node-backend            |       at Dicer._oninfo (/app/node_modules/dicer/lib/Dicer.js:190:36)
node-backend            |       at SBMH.<anonymous> (/app/node_modules/dicer/lib/Dicer.js:126:10)
node-backend            |       at SBMH.emit (node:events:390:28) {
node-backend            |     locations: [ [Object] ],
node-backend            |     path: [ 'createProduct' ]
node-backend            |   }

Solution in my case: wrap stream in promise

export const resolvers = {
  // ... other resolvers ...
  Mutation: {
    uploadImageResolver: async (_, { image }) => {
      // throwing error
      await new Promise(async (res, rej) => {
        const { createReadStream } = await image;
        const stream = createReadStream();
        stream.on("error", (err) => {
            rej(err);
        });

        // ... some code about using that stream, like save file ...
        // await saveFile(stream);
        res(); // success
      });
    },
  },
};

1reaction
roytan883commented, Aug 16, 2018

@jaydenseric I use apollo-server-koa, how can i fix this? wait apollo-server-koa use new version of apollo-upload-server ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix the upload_max_filesize Error in WordPress
Method 1. Editing the .htaccess File ... The quickest fix for the uploaded file exceeds the upload_max_filesize directive in php.ini error is ...
Read more >
PHP File Upload greater than upload_max_filesize and error
The error is in $_FILES['userfile']['error'] . You just have to check that this value is UPLOAD_ERR_INI_SIZE to detect if the file is bigger ......
Read more >
The Uploaded File Exceeds the upload_max_filesize Directive ...
If the file size of the upload exceeds the maximum upload size configuration on your hosting server, you'll see this error message. The...
Read more >
Increase Upload Max File Size on Localhost Server XAMPP or ...
MAMP #XAMPP # Upload Files SizeOne of the biggest issues we experience with local servers or servers in general is the default limits...
Read more >
Server crashes with error 500 when uploading 100mb file
I'm trying to upload a 100MB zip file to my server but it just crashes. I got some error logs saying that it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found