Navigation Menu

Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mwawrusch committed Nov 24, 2012
0 parents commit bc21ab2
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.8
- 0.9
20 changes: 20 additions & 0 deletions 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 changes: 41 additions & 0 deletions 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 changes: 114 additions & 0 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions 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 changes: 64 additions & 0 deletions 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 changes: 8 additions & 0 deletions 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 changes: 5 additions & 0 deletions test/mocha.opts
@@ -0,0 +1,5 @@
--require assert
--require should
--globals name
--compilers coffee:coffee-script
--timeout 10s

0 comments on commit bc21ab2

Please sign in to comment.