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

gbox-errors

v2.3.9

Published

Error handlers

Downloads

9

Readme

Build as support for Gauss Box API. Works with Sails.js only.

Build and format more readable error response for GaussBox.

Install

$ npm install --save gbox-errors

Config parameters

{
    "environment": "app environment",
    "packageJson": { content of package.json file}
    "emailConfig": {
        "host": "mail server host",
        "port": "mail server post",
        "user": "mail server username",
        "pass": "mail server password",
        "errorNotification": true,     // would be used for error notifications
        "contacts": ['[email protected]'],
        "status": [500]     // for which http status codes mail would be sent
    },
    "sentry": {
        "configuration": {
            "dsn": "sentry dsn url"
        },
        "user": { user params for log outputs }
        "tags": { "tagKey": "tagValue", ... },
        "level": "error",
        "extra": { "key": "value", ... },
        "breadcrumb": {
            "message": "",
            "category": "",
            "level": ""
        }
    }

}
  • environment - in production environment, error details would not be sent
  • packageJson - this is used for detailed error output like apiName, version etc.
  • sentry - this is used for sending error logs to sentry (only dsn is required, if some parameter is not set, then sentry defaults is used)
  • sentry.configuration - this is sentry configuration options (dsn and environment is required, other is set only if provided)
  • sentry.user - user details for filtering log outputs
  • sentry.tags - tags for filtering log outputs
  • sentry.level - you can set the severity of an event to one of five values: ‘fatal’, ‘error’, ‘warning’, ‘info’, and ‘debug’. (‘error’ is the default.) ‘fatal’ is the most severe and ‘debug’ is the least.
  • sentry.extra - in addition to the structured context that Sentry understands, you can send arbitrary key/value pairs of data which will be stored alongside the event. These are not indexed and are simply used to add additional information about what might be happening
  • sentry.breadcrumb - sentry breadcrumb options

Usage in response

//Handle error in response
const formatError = require('gbox-errors')(config);

let error = formatError.format(data);

return this.res.status(error.status).json(error.response);

Usage in controller

* optional

//status is number and message is string with min i char needed.
res.negotiate([status,message,options*])


//Example

res.negotiate([404,'Document id not found.']);

//Example with option

res.negotiate([404,'Document id not found.','Document Controller']);

Handle GOT err response

//Example
return this.res.status(error.response.body.error.statusCode).json(error.response.body);

Response

   * on error response data object is always empty
   * message object is for frontend and client

   //if sails run development mode, response extends with object error (see example)

    * apiTrace showing some info from package.json
    * errorTrace trace where error came from (if error can't be traced, errorTrace is removed)
//Example
//Production mode

{
    "data": [],
    "message": "Document fail"
}

//Example
//Development mode

{
    "data": [],
    "message": "Cannot read property 'body' of undefined",
    "error": {
        "statusCode": 500,
        "payload": {
            "statusCode": 500,
            "error": "Internal Server Error",
            "message": "Cannot read property 'body' of undefined"
        },
        "details": {
            "errorTrace": {
                "trace_1": {
                    "source": "at  (C:\\node_project\\Gbox v2\\erp\\documentApi\\api\\controllers\\document\\create.js:541:54)",
                    "lineNumber": 541,
                    "columnNumber": 54,
                    "fileName": "v2\\erp\\documentApi\\api\\controllers\\document\\create.js"
                }
            },
            "apiTrace": {
                "apiName": "document-api",
                "gboxErrorsVersion": "^2.2.3",
                "sqlVersion": "1.0.0",
                "sailsVersion": "1.0.2"
            },
            "generateBy": "gbox-errors ^2.2.3"
        },
        "validator": "5xx",
        "code": "UNHANDLED_ERROR",
        "enviroment": "development",
        "serverTime": "2018-9-18 13:33:16",
        "development": "TypeError: Cannot read property 'body' of undefined\n    at Object.sails.getDatastore.transaction [as during] (C:\\node_project\\Gbox v2\\erp\\documentApi\\api\\controllers\\document\\create.js:541:54)\n    at <anonymous>"
    }
}

Helper

    /* if u need fast list */

    const notification = require('npm-gbErrors')();

    notification.errorList(); //Return list of available statuses

Available status

    * 400 badRequest
    * 401 unauthorized
    * 402 paymentRequired
    * 403 forbidden
    * 404 notFound
    * 405 methodNotAllowed
    * 406 notAcceptable
    * 407 proxyAuthRequired
    * 408 clientTimeout
    * 409 conflict
    * 410 resourceGone
    * 411 lengthRequired
    * 412 preconditionFailed
    * 413 entityTooLarge
    * 414 uriTooLong
    * 415 unsupportedMediaType
    * 416 rangeNotSatisfiable
    * 417 expectationFailed
    * 422 badData
    * 423 locked
    * 424 failedDependency
    * 428 preconditionRequired
    * 429 tooManyRequests
    * 451 illegal

Created by

Dejan Kubaša, Gauss d.o.o.