
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
miller-handler
Advanced tools
REST API Error Messages Generator Node Module - Módulo para generación de mensajes de error .
REST API Error Messages Generator - Module to automate and standardize error messages on REST API based services.
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').
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.'
}
*/
You can modify, enable and disable every key of the object message, just like the following examples:
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
}
*/
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'
}
*/
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'
}
*/
const Mhandler = new mhandler('en')
MHandler.Custom('a085512', 'RandomError', 'Dang!')
/* will return
{
status: 'error',
code: 'a085512',
name: 'RandomError',
message: 'Dang!'
}
*/
FAQs
REST API Error Messages Generator Node Module - Módulo para generación de mensajes de error .
We found that miller-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.