Skip to content

Instantly share code, notes, and snippets.

@MauriceButler
Created March 9, 2016 00:55
Show Gist options
  • Save MauriceButler/c568a53718b69d8cf263 to your computer and use it in GitHub Desktop.
Save MauriceButler/c568a53718b69d8cf263 to your computer and use it in GitHub Desktop.
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var errors = require('generic-errors');
console.log(new errors.NotFound().stack);
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){function BaseError(data){var oldLimit=Error.stackTraceLimit,error;Error.stackTraceLimit=20;error=Error.apply(this,arguments);Error.stackTraceLimit=oldLimit;if(Error.captureStackTrace){Error.captureStackTrace(this,BaseError)}this.__genericError=true;if(typeof data==="string"){this.message=data}else{for(var key in data){this[key]=data[key]}if(!this.message&&data&&data.message){this.message=data.message}}if(!this.message){this.message=this.toString()}}BaseError.prototype=Object.create(Error.prototype);BaseError.prototype.constructor=BaseError;BaseError.prototype.toString=function(){return this.message||this.code+": "+this.constructor.name};BaseError.prototype.valueOf=function(){return this};BaseError.prototype.toJSON=function(){var result={};for(var key in this){if(typeof this[key]!=="function")result[key]=this[key]}return result};BaseError.prototype.code=500;BaseError.isGenericError=function(obj){return obj instanceof BaseError||obj!=null&&obj.__genericError};module.exports=BaseError},{}],2:[function(require,module,exports){var BaseError=require("./baseError");function Forbidden(){BaseError.apply(this,arguments);Error.captureStackTrace(this,Forbidden)}Forbidden.prototype=Object.create(BaseError.prototype);Forbidden.prototype.constructor=Forbidden;Forbidden.prototype.code=403;module.exports=Forbidden},{"./baseError":1}],3:[function(require,module,exports){var BaseError=require("./baseError");function NotFound(){BaseError.apply(this,arguments);Error.captureStackTrace(this,NotFound)}NotFound.prototype=Object.create(BaseError.prototype);NotFound.prototype.constructor=NotFound;NotFound.prototype.code=404;module.exports=NotFound},{"./baseError":1}],4:[function(require,module,exports){var BaseError=require("./baseError");function PreconditionFailed(){BaseError.apply(this,arguments);Error.captureStackTrace(this,PreconditionFailed)}PreconditionFailed.prototype=Object.create(BaseError.prototype);PreconditionFailed.prototype.constructor=PreconditionFailed;PreconditionFailed.prototype.code=412;module.exports=PreconditionFailed},{"./baseError":1}],5:[function(require,module,exports){var BaseError=require("./baseError");function Teapot(){BaseError.apply(this,arguments);Error.captureStackTrace(this,Teapot)}Teapot.prototype=Object.create(BaseError.prototype);Teapot.prototype.constructor=Teapot;Teapot.prototype.code=418;module.exports=Teapot},{"./baseError":1}],6:[function(require,module,exports){var BaseError=require("./baseError");function Unauthorised(){BaseError.apply(this,arguments);Error.captureStackTrace(this,Unauthorised)}Unauthorised.prototype=Object.create(BaseError.prototype);Unauthorised.prototype.constructor=Unauthorised;Unauthorised.prototype.code=401;module.exports=Unauthorised},{"./baseError":1}],7:[function(require,module,exports){var BaseError=require("./baseError");function Unprocessable(){BaseError.apply(this,arguments);Error.captureStackTrace(this,Unprocessable)}Unprocessable.prototype=Object.create(BaseError.prototype);Unprocessable.prototype.constructor=Unprocessable;Unprocessable.prototype.code=422;module.exports=Unprocessable},{"./baseError":1}],"generic-errors":[function(require,module,exports){var constructors={BaseError:require("./baseError"),Forbidden:require("./forbidden"),Unauthorised:require("./unauthorised"),NotFound:require("./notFound"),Unprocessable:require("./unprocessable"),PreconditionFailed:require("./preconditionFailed"),Teapot:require("./teapot")};for(var key in constructors){constructors[constructors[key].prototype.code]=constructors[key]}module.exports=constructors},{"./baseError":1,"./forbidden":2,"./notFound":3,"./preconditionFailed":4,"./teapot":5,"./unauthorised":6,"./unprocessable":7}]},{},[]);var errors=require("generic-errors");console.log((new errors.NotFound).stack);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"generic-errors": "2.0.2"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment