yahoo/fumble

Name: fumble

Owner: Yahoo Inc.

Description: Simple error objects in node. Created specifically to be used with https://github.com/yahoo/fetchr and based on https://github.com/hapijs/boom

Created: 2015-02-24 14:02:09.0

Updated: 2016-11-15 01:38:37.0

Pushed: 2016-10-11 22:54:45.0

Homepage: null

Size: 18

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

fumble

npm version Build Status Dependency Status devDependency Status Coverage 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
fumble = require('fumble');

callAndProcess = require('./callAndProcess');

le.exports = require('api').base.service({
name: 'foo',
read: function (req, resource, params, context, callback) {
    switch(resource) {
        case this.name: 
            callAndProcess(req, params, context, callback);
            return;
    }

    var 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

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

Generate an HttpError object where

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

le.http.badRequest('invalid query');

ssentially generates

statusCode: 400,
message: 'invalid query'

===

fumble.http.unauthorized ([message='Unauthorized'], [options])

returns an HTTP status code of 401

le.http.unauthorized('not logged in');

ssentially generates

statusCode: 401,
message: 'not logged in'

===

fumble.http.forbidden ([message='Forbidden'], [options])

returns an HTTP status code of 403

le.http.forbidden('top secret');

ssentially generates

statusCode: 403,
message: 'top secret'

===

fumble.http.notFound ([message='Not Found'], [options])

returns an HTTP status code of 404

le.http.notFound('does not exist');

ssentially generates

statusCode: 404,
message: 'does not exist'

===

fumble.http.methodNotAllowed ([message='Method Not Allowed'], [options])

returns an HTTP status code of 405

le.http.methodNotAllowed('not allowed');

ssentially generates

statusCode: 405,
message: 'not allowed'

===

fumble.http.proxyAuthenticationRequired ([message='Proxy Authentication Required'], [options])

returns an HTTP status code of 407

le.http.proxyAuthenticationRequired('need to login to foo');

ssentially generates

statusCode: 407,
message: 'need to login to foo'

===

fumble.http.conflict ([message='Conflict'], [options])

returns an HTTP status code of 409

le.http.conflict('collision detected');

ssentially generates

statusCode: 409,
message: 'collision detected'

===

fumble.http.gone ([message='Gone'], [options])

returns an HTTP status code of 410

le.http.gone('bye bye');

ssentially generates

statusCode: 410,
message: 'bye bye'

fumble.http.preconditionFailed ([message='Precondition Failed'], [options])

returns an HTTP status code of 412

le.http.preconditionFailed('missing CLA');

ssentially generates

statusCode: 412,
message: 'missing CLA'

===

fumble.http.tooManyRequests ([message='Too Many Requests'], [options])

returns an HTTP status code of 429

le.http.tooManyRequests('slow down');

ssentially generates

statusCode: 429,
message: 'slow down'

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

returns an HTTP status code of 500

le.http.internalServerError('unkown error');

ssentially generates

statusCode: 500,
message: 'unknown error'

===

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

returns an HTTP status code of 501

le.http.notImplemented('missing enhancement');

ssentially generates

statusCode: 501,
message: 'missing enhancement'

===

fumble.http.badGateway ([message='Bad Gateway'], [options])

returns an HTTP status code of 502

le.http.badGateway('mongo error');

ssentially generates

statusCode: 502,
message: 'mongo error'

===

fumble.http.serviceUnavailable ([message='Service Unavailable'], [options])

returns an HTTP status code of 503

le.http.serviceUnavailable('feeds are down');

ssentially 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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.