Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit bc21ab20ff3aefafa0b97a57786a0550bf3ec84c 0 parents
@mwawrusch mwawrusch authored
15 .gitignore
@@ -0,0 +1,15 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
4 .travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.8
+ - 0.9
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Martin Wawrusch
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 README.md
@@ -0,0 +1,41 @@
+node-some-errors
+===========================
+
+npm install some-errors
+
+This is a collection of node.js error classes that we use internally. If you need them, use them.
+
+## Release Notes
+
+### 0.2.0
+* First version
+
+## Internal Stuff
+
+* npm run-script watch
+
+## Publish new version
+
+* Change version in package.json
+git add . -A
+git commit -m "Upgrading to v0.2.0"
+git tag -a v0.2.7 -m 'version 0.2.0'
+git push --tags
+npm publish
+
+## Contributing to node-some-errors
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
+* Fork the project
+* Start a feature/bugfix branch
+* Commit and push until you are happy with your contribution
+* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
+* Please try not to mess with the package.json, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
+
+## Copyright
+
+Copyright (c) 2012 Martin Wawrusch See LICENSE for
+further details.
+
+
114 lib/index.js
@@ -0,0 +1,114 @@
+// Generated by CoffeeScript 1.4.0
+(function() {
+ var AccessDenied, AccessDeniedUserRequired, ClearPassportSession, NotFound, UnprocessableEntity,
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+ exports.NotFound = NotFound = (function(_super) {
+
+ __extends(NotFound, _super);
+
+ function NotFound(path) {
+ this.name = 'NotFound';
+ this.status = 404;
+ if (path) {
+ Error.call(this, "Cannot find " + path);
+ this.path = path;
+ } else {
+ Error.call(this, "Not Found");
+ }
+ Error.captureStackTrace(this, arguments.callee);
+ }
+
+ return NotFound;
+
+ })(Error);
+
+ exports.ClearPassportSession = ClearPassportSession = (function(_super) {
+
+ __extends(ClearPassportSession, _super);
+
+ function ClearPassportSession(path) {
+ this.path = path;
+ this.name = 'ClearPassportSession';
+ this.message = "Could not find user";
+ this.status = 401;
+ Error.call(this, this.message);
+ Error.captureStackTrace(this, arguments.callee);
+ }
+
+ return ClearPassportSession;
+
+ })(Error);
+
+ exports.AccessDenied = AccessDenied = (function(_super) {
+
+ __extends(AccessDenied, _super);
+
+ function AccessDenied(path) {
+ this.path = path;
+ this.name = 'AccessDenied';
+ this.message = "You cannot access the resource " + this.path;
+ this.status = 401;
+ Error.call(this, this.message);
+ Error.captureStackTrace(this, arguments.callee);
+ }
+
+ return AccessDenied;
+
+ })(Error);
+
+ exports.AccessDeniedUserRequired = AccessDeniedUserRequired = (function(_super) {
+
+ __extends(AccessDeniedUserRequired, _super);
+
+ function AccessDeniedUserRequired(path) {
+ this.path = path;
+ this.name = 'AccessDenied';
+ this.message = "You cannot access the resource " + this.path + " because a user is required.";
+ this.status = 401;
+ Error.call(this, this.message);
+ Error.captureStackTrace(this, arguments.callee);
+ }
+
+ return AccessDeniedUserRequired;
+
+ })(Error);
+
+ exports.UnprocessableEntity = UnprocessableEntity = (function(_super) {
+
+ __extends(UnprocessableEntity, _super);
+
+ function UnprocessableEntity(parameter) {
+ this.parameter = parameter;
+ this.name = 'UnprocessableEntity';
+ this.message = "At least one parameter is missing or invalid " + this.parameter;
+ this.status = 422;
+ Error.call(this, this.message);
+ Error.captureStackTrace(this, arguments.callee);
+ }
+
+ return UnprocessableEntity;
+
+ })(Error);
+
+ /*
+ Check if we have an error, indicating not found if @see item is null
+ @example
+ return if errors.isError(...)
+ */
+
+
+ exports.isError = function(err, item, itemUrl, next) {
+ if (err) {
+ next(err);
+ return true;
+ }
+ if (!item) {
+ next(new exports.NotFound(itemUrl));
+ return true;
+ }
+ return false;
+ };
+
+}).call(this);
44 package.json
@@ -0,0 +1,44 @@
+{
+ "author": "Martin Wawrusch <martin@wawrusch.com> (http://martinatsunset.com)",
+ "name": "some-errors",
+ "description": "Some error objects prepackaged.",
+ "version": "0.2.0",
+ "main" : "lib/index.js",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/codedoctor/node-some-errors.git"
+ },
+ "bin" : {
+ },
+ "directories" : {
+ "lib" : "./lib",
+ "test" : "./test"
+ },
+ "keywords" : [
+ "errors"
+ ],
+ "scripts": {
+ "prepublish" : "coffee -c -o lib src",
+ "watch" : "coffee -c -w -o lib src",
+ "test": "coffee -c -o lib src;NODE_ENV=test node_modules/.bin/mocha --timeout 10000 -R spec test/*.coffee"
+ },
+ "engines": {
+ "node": ">=0.8.0"
+ },
+ "dependencies": {
+
+ },
+ "devDependencies": {
+ "async": "0.1.22",
+ "coffee-script": "1.4.0",
+ "should": "1.2.1",
+ "mocha": "1.6.0"
+ },
+ "bugs": { "url": "http://github.com/codedoctor/node-some-errors/issues" },
+ "licenses": [
+ { "type": "MIT",
+ "url": "http://github.com/codedoctor/node-some-errors/raw/master/LICENSE"
+ }
+ ]
+
+}
64 src/index.coffee
@@ -0,0 +1,64 @@
+# Inherit from `Error.prototype`.
+
+exports.NotFound = class NotFound extends Error
+ constructor: (path) ->
+ @name = 'NotFound'
+ @status = 404
+
+ if path
+ Error.call @, "Cannot find #{path}"
+ @path = path
+ else
+ Error.call @, "Not Found"
+
+ Error.captureStackTrace @, arguments.callee
+
+exports.ClearPassportSession = class ClearPassportSession extends Error
+ constructor: (@path) ->
+ @name = 'ClearPassportSession'
+ @message = "Could not find user"
+ @status = 401
+
+ Error.call @, @message
+ Error.captureStackTrace @, arguments.callee
+
+exports.AccessDenied = class AccessDenied extends Error
+ constructor: (@path) ->
+ @name = 'AccessDenied'
+ @message = "You cannot access the resource #{@path}"
+ @status = 401
+
+ Error.call @, @message
+ Error.captureStackTrace @, arguments.callee
+
+exports.AccessDeniedUserRequired = class AccessDeniedUserRequired extends Error
+ constructor: (@path) ->
+ @name = 'AccessDenied'
+ @message = "You cannot access the resource #{@path} because a user is required."
+ @status = 401
+
+ Error.call @, @message
+ Error.captureStackTrace @, arguments.callee
+
+exports.UnprocessableEntity = class UnprocessableEntity extends Error
+ constructor: (@parameter) ->
+ @name = 'UnprocessableEntity'
+ @message = "At least one parameter is missing or invalid #{@parameter}"
+ @status = 422
+
+ Error.call @, @message
+ Error.captureStackTrace @, arguments.callee
+
+###
+Check if we have an error, indicating not found if @see item is null
+@example
+return if errors.isError(...)
+###
+exports.isError = (err, item, itemUrl, next) ->
+ if err
+ next(err)
+ return true
+ unless item
+ next(new exports.NotFound(itemUrl))
+ return true
+ false
8 test/basic-existenz-test.coffee
@@ -0,0 +1,8 @@
+assert = require 'assert'
+should = require 'should'
+
+describe 'WHEN loading the module', ->
+ index = require '../lib/index'
+
+ it 'should exist', ->
+ should.exist index
5 test/mocha.opts
@@ -0,0 +1,5 @@
+--require assert
+--require should
+--globals name
+--compilers coffee:coffee-script
+--timeout 10s
Please sign in to comment.
Something went wrong with that request. Please try again.