GithubHelp home page GithubHelp logo

mongoose-error-beautify's Introduction

mongoose-error-beautify

A simple module to format mongoose errors with ease

installation

Using npm:

$ npm install mongoose-error-beautify

or using yarn:

$ yarn add mongoose-error-beautify

usage

const mongooseErrorBeautify = require("mongoose-error-beautify");

try {
  const user = new User({
    // name: "John",
    // age: 6,
    // password: "123",
  });

  await user.save();

} catch (error) {
  console.log(error);

  // Error: User validation failed: username: Username must be provided, email: Email must be provided
  //     at ValidationError.inspect (D:\NodeJS\mongoose-error-beautify\node_modules\mongoose\lib\error\validation.js:48:26)
  //     at formatValue (node:internal/util/inspect:782:19)
  //     at inspect (node:internal/util/inspect:347:10)
  //     at formatWithOptionsInternal (node:internal/util/inspect:2167:40)
  //     at formatWithOptions (node:internal/util/inspect:2029:10)
  //     at console.value (node:internal/console/constructor:324:14)
  //     at console.log (node:internal/console/constructor:360:61)
  //     at init (D:\NodeJS\mongoose-error-beautify\server.js:24:13)
  //     at processTicksAndRejections (node:internal/process/task_queues:96:5

  console.log(mongooseErrorBeautify(error));
  [
    {
      message: 'Username must be provided',
      path: 'username'
    },
    {
      message: 'Email must be provided',
      path: 'email'
    },
    errorType: 'ValidationError'
  ]
}

mongoose-error-beautify's People

Contributors

ssakib4040 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.