happy-waterline-errors

0.1.0 • Public • Published

happy-waterline-errors

i want to be happy handling waterline errors

🚧 It is a bad idea to use this module! I made it to lessen my work! And it is not yet comprehensive! 🚧

node npm Travis Gemnasium Coveralls

usage:

import happy from "happy-waterline-errors";
 
// formats errors from Waterline to make them more user-friendly
// you can even send it back to your users as response! I do that!
User
  .create({ firstName: "gocho" })
  .exec(function(error, user) {
    if (error) {
      return console.log("user-friendly error: %j", happy(error));
    }
 
    return console.log("user: %j", error);
  })

API:

import happy from "happy-waterline-errors";

happy(error [, options])

Formats waterline error. You can provide options.

  • options (Object):
    • key (Function): function may be used to format attribute keys

errors:

validation errors:

{
  code: "err_validation",
  status: 422,
  message: "validation failed",
  description: [
    {
      field: "email",
      rules: [
        "email",
      ],
    },
    {
      field: "lastName",
      rules: [
        "required",
        "string",
      ],
    },
  ],
}

unknown errors:

{
  code: "err_unknown",
  status: 500,
  message: "unknown error",
}

forbidden errors:

{
  code: "err_forbidden",
  status: 403,
  message: "action is forbidden",
}

license:

The MIT License (MIT)

Copyright (c) 2015 GochoMugo mugo@forfuture.co.ke

Package Sidebar

Install

npm i happy-waterline-errors

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • gochomugo