0.1.0 • Published 9 years ago

happy-waterline-errors v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

happy-waterline-errors

i want to be happy handling waterline errors

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

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