npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

miller-handler

v0.7.0

Published

REST API Error Messages Generator Node Module - Módulo para generación de mensajes de error .

Downloads

6

Readme

miller-handler v0.7.0

REST API Error Messages Generator - Module to automate and standardize error messages on REST API based services.

Implementation

You should specify the default language displayed en error messages directly on the class instantiation.

//Import
const mhandler = require('mhandler')

//Instantiation, english by default
const Mhandler =  new mhandler()

//Instantiation with Spanish as default language
const Mhandler =  new mhandler('es')

Note: Currently, the ​​available languages for displaying error messages are English ('en') and Spanish ('es').

Basic usage


try{
//...
}catch (e){
 //...
 return res.send(500, Mhandler.InternalError())
}

/* will return
  {
   status: 'error',
   code: 'E08',
   name: 'UnavailableService',
   message: 'The method to the specified resource is currently unavailable.'
  }
*/

For example, if you want to display which fields are empty inside a certain incoming request.


try{
  //...
}catch (e){
  //...
  return res.send(500, Mhandler.EmptyFields('firstName', 'lastName'))
}

/* will return
  {
   status: 'error',
   code: 'E01',
   name: 'RequiredEmptyField',
   message: 'Should complete the following field(s): firstName, lastName.'
  }
*/

Customization Options

You can modify, enable and disable every key of the object message, just like the following examples:

Case 1: Activating message timestamps

const mhandler = require('mhandler')

//On class instantiation
const Mhandler =  new mhandler('en',{timestamp: true})

/* will return
  {
   status: 'error',
   name: 'InternalError',
   message: 'Something went wrong.',
   timestamp: 2019-05-19T07:55:46.643Z
  }
*/

Case 2: Omit object message properties

const mhandler = require('mhandler')

//On class instantiation
const Mhandler =  new mhandler('en',{code: false})

/* will return
  {
   status: 'error',
   name: 'InternalError',
   message: 'Something went wrong.'
  }
*/

//Or setting the object properties wherever you want
const Mhandler =  new mhandler('en')

Mhandler.setMod({name:false, message: false})

/* will return
  {
   status: 'error',
   code: 'E006'
  }
*/

Case 3: Modifying the object message properties

Note: the object message modifiers only works fine alongside the default object message template:

const Mhandler =  new mhandler('en',{
    code: 'errorCode',
    message: 'detail'
  })

/* will return
  {
   status: 'error',
   errorCode: 'E005',
   name: 'InternalError',
   detail: 'Something went wrong.'
  }
*/

//Or
const Mhandler = new mhandler()

Mhandler.setMod({name:false, status: 'type'})

/* will return
  {
   type: 'error',
   code: 'E056',
   message: 'Some error'
  }
*/

Case 4: Using Custom Errors

const Mhandler =  new mhandler('en')

MHandler.Custom('a085512', 'RandomError', 'Dang!')

/* will return
  {
   status: 'error',
   code: 'a085512',
   name: 'RandomError',
   message: 'Dang!'
  }
*/

Available Errors

Validation Errors

Resource Errors

Authentication & Authorization Errors

Server Errors

Other

Official npm package