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

fumble

v0.1.9

Published

Simple error objects in node. Created specifically to be used with the fetchr library and based on hapi.js' Boom.

Downloads

3,989

Readme

fumble

npm version Build Status

Join the chat at https://gitter.im/yahoo/fumble

Simple error objects in node. Created specifically to be used with the fetchr library and based on hapi.js' Boom.

eli manning

Usage

import fumble from 'fumble';
import callAndProcess from './callAndProcess';
import api from 'api';

export default api.base.service({
    name: 'foo',
    read: function (req, resource, params, context, callback) {
        switch(resource) {
            case this.name: 
                callAndProcess(req, params, context, callback);
                return;
        }
        
        const error = fumble.http.create(400, 'Passed in an invalid resource', {
            debug: [resource]
        });
        
        req.error(error);
        req.debug(error.stack); // nice stack trace
        /**
        * logs:
        * { [HttpError: Bad Request] statusCode: 400, message: 
        * 'Passed in an invalid resource', debug: [ resource ] }
        */

        callback(error);
    }
});

API Docs

fumble.http

provides a set of utilities for returning HTTP errors. Each method returns an HttpError instance, which itself extends the native Error class (which means you can access the stack prop on your error instance). Each error has the following two props:

  • statusCode {Number} - the HTTP status code (typically 4xx or 5xx).
  • message {String} - the error message

fumble.http.create ([status=500], [message='Internal Server Error'], [options])

Generate an HttpError object where:

  • statusCode - an HTTP error code number. Must be greater or equal 400
  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
const error = fumble.http.create(400, 'missing params', { debug: [passedInParams] });

HTTP 4xx Errors

fumble.http.badRequest ([message='Bad Request'], [options])

returns an HTTP status code of 400

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.badRequest('invalid query');

// essentially generates
{
    statusCode: 400,
    message: 'invalid query'
}
fumble.http.unauthorized ([message='Unauthorized'], [options])

returns an HTTP status code of 401

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.unauthorized('not logged in');

// essentially generates
{
    statusCode: 401,
    message: 'not logged in'
}
fumble.http.forbidden ([message='Forbidden'], [options])

returns an HTTP status code of 403

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.forbidden('top secret');

// essentially generates
{
    statusCode: 403,
    message: 'top secret'
}
fumble.http.notFound ([message='Not Found'], [options])

returns an HTTP status code of 404

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.notFound('does not exist');

// essentially generates
{
    statusCode: 404,
    message: 'does not exist'
}
fumble.http.methodNotAllowed ([message='Method Not Allowed'], [options])

returns an HTTP status code of 405

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.methodNotAllowed('not allowed');

// essentially generates
{
    statusCode: 405,
    message: 'not allowed'
}
fumble.http.proxyAuthenticationRequired ([message='Proxy Authentication Required'], [options])

returns an HTTP status code of 407

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.proxyAuthenticationRequired('need to login to foo');

// essentially generates
{
    statusCode: 407,
    message: 'need to login to foo'
}
fumble.http.conflict ([message='Conflict'], [options])

returns an HTTP status code of 409

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.conflict('collision detected');

// essentially generates
{
    statusCode: 409,
    message: 'collision detected'
}
fumble.http.gone ([message='Gone'], [options])

returns an HTTP status code of 410

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.gone('bye bye');

// essentially generates
{
    statusCode: 410,
    message: 'bye bye'
}
fumble.http.preconditionFailed ([message='Precondition Failed'], [options])

returns an HTTP status code of 412

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.preconditionFailed('missing CLA');

// essentially generates
{
    statusCode: 412,
    message: 'missing CLA'
}
fumble.http.tooManyRequests ([message='Too Many Requests'], [options])

returns an HTTP status code of 429

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.tooManyRequests('slow down');

// essentially generates
{
    statusCode: 429,
    message: 'slow down'
}

HTTP 5xx Errors

fumble.http.internalServerError ([message='Internal Server Error'], [options])

returns an HTTP status code of 500

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.internalServerError('unkown error');

// essentially generates
{
    statusCode: 500,
    message: 'unknown error'
}

===

fumble.http.notImplemented ([message='Not Implemented'], [options])

returns an HTTP status code of 501

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.notImplemented('missing enhancement');

// essentially generates
{
    statusCode: 501,
    message: 'missing enhancement'
}
fumble.http.badGateway ([message='Bad Gateway'], [options])

returns an HTTP status code of 502

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.badGateway('mongo error');

// essentially generates
{
    statusCode: 502,
    message: 'mongo error'
}
`fumble.http.serviceUnavailable ([message='Service Unavailable'], [options])

returns an HTTP status code of 503

  • message - optional message string.
  • options - extra options
  • options.debug - additional error debug info set to error.debug property.
fumble.http.serviceUnavailable('feeds are down');

// essentially generates
{
    statusCode: 503,
    message: 'feeds are down'
}

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE file for license text and copyright information.