title: next js, can't catch errors in multer
body: <p>I'm trying to upload files using next js and multer. I use digitalOcean spaces which is compatible with aws s3 sdk:</p>
  <p>this is my s3 config:</p>
  <pre><code>const spacesEndpoint = new aws.Endpoint(&quot;fra1.digitaloceanspaces.com&quot;);
  const s3 = new aws.S3({
    endpoint: spacesEndpoint,
    accessKeyId: process.env.SPACES_KEY_ID,
    secretAccessKey: process.env.SPACES_KEY_SECRET,
  });
  </code></pre>
  <p>this is multer config:</p>
  <pre><code>const upload = multer({
    storage: multerS3({
      s3: s3,
      bucket: &quot;pdf&quot;,
      acl: &quot;public-read&quot;,
      key: function (req, file, cb) {
        console.log(&quot;file&quot;, file);
        try {
          cb(null, file.originalname);
        } catch (err) {
          console.log(err);
        }
      },
    }),
  }).array(&quot;files&quot;);
  </code></pre>
  <p>I'm also invoking multer by myself to catch the errors as the multer doc say but i get referece error &quot;err is not defined&quot;</p>
  <pre><code>apiRoute.post((req, res) =&gt; {
    console.log(req.body);
  
    upload(req, res, function (err) {
      if (err instanceof multer.MulterError) {
        // A Multer error occurred when uploading.
      } else if (err) {
        // An unknown error occurred when uploading.
      }
  
      // Everything went fine.
    });
    res.status(200).json({ data: &quot;success&quot; });
  });
  </code></pre>
  <p>I can also post a code where i'm doing the axios call to the api route but right now i just want to see any more information than 500 status code response form the server</p>
  <p>thsis the only error i'm getting: Error: Request failed with status code 500</p>