UNPKG

node-rigorous

Version:
35 lines (25 loc) 859 B
const uniqid = require('uniqid'); module.exports = class RigorousError extends Error { constructor(name, detail = null) { super(); this.id = uniqid(); this.date = new Date(); if (process.env.NODE_ENV === 'development') { this.name = name.dev; this.detail = detail; } else { this.name = name.prod === '' ? 'GENERIC_ERROR' : name.prod; this.detail = null; } this.reasons = null; if (this.detail !== null) { this.reasons = []; if (detail.name === 'ValidationError') { Object.values(detail.errors).forEach((value) => { console.log('Value error:', value); this.reasons.push(value.reason.name); }); } } } };