How to use the multer.MulterError function in multer

To help you get started, we’ve selected a few multer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cdimascio / express-openapi-validator / src / middlewares / openapi.multipart.ts View on Github external
function error(req, err) {
  if (err instanceof multer.MulterError) {
    // TODO is special handling for MulterErrors needed
    console.error(err);
    return validationError(500, req.path, err.message);
  } else {
    // HACK
    // TODO improve multer error handling
    const missingField = /Multipart: Boundary not found/i.test(
      err.message || '',
    );
    if (missingField) {
      return validationError(400, req.path, 'multipart file(s) required');
    } else {
      console.error(err);
      return validationError(500, req.path, err.message);
    }
  }
github stanford-oval / almond-cloud / util / error_handling.js View on Github external
function json(err, req, res, next) {
    let message = err.message;

    if (err instanceof multer.MulterError) {
        res.status(400);
    } else if (err instanceof jwt.JsonWebTokenError) {
        res.status(403);
    } else if (typeof err.status === 'number') {
        // oauth2orize errors, bodyparser errors
        res.status(err.status);
    } else if (typeof err.code === 'number') {
        res.status(err.code);
    } else if (err.code === 'ENOENT') {
        res.status(404);
    } else if (err.code === 'EPERM') {
        res.status(403);
    } else if (err.code === 'EINVAL') {
        res.status(400);
    } else {
        res.status(500);
github luizbatanero / gostack-meetapp / api / src / app.js View on Github external
this.server.use(async (err, req, res, next) => {
      if (
        process.env.NODE_ENV === 'development' ||
        err instanceof multer.MulterError
      ) {
        return res.status(500).json({
          error: err,
        });
      }

      return res.status(500).json({ error: 'Internal server error' });
    });
  }
github jkhuangfu / node_server / routes / common.js View on Github external
upload(req,res,err=>{
            if (err instanceof multer.MulterError) {
                res.json({code:102,msg:err.message});
                return false;
            } else if (err) {
                res.json({code:101,mag:err});
                return false;
            }
            upFileForOss(req, res);
        })
    })
github lincenying / mmf-blog-vue2-pwa-ssr / server / api / app-shihua.js View on Github external
upload(req, res, function(err) {
        if (err instanceof multer.MulterError) {
            res.send({ code: '-200', msg: err.toString() })
        } else if (err) {
            res.send({ code: '-200', msg: err.toString() })
        } else {
            const file = req.file
            res.send({ code: '200', url: file.path })
        }
    })
}
github jkhuangfu / node_server / routes / common.js View on Github external
upload(req,res,err=>{
            if (err instanceof multer.MulterError) {
                res.json({code:102,msg:err.message});
                return false;
            } else if (err) {
                res.json({code:101,mag:err});
                return false;
            }
            upFileForLocal(req, res);
        })
    });

multer

Middleware for handling `multipart/form-data`.

MIT
Latest version published 2 years ago

Package Health Score

76 / 100
Full package analysis