Permalink
Browse files

throw proper Error objects

  • Loading branch information...
1 parent c1095af commit 36130adaf74aad4e0208d1a8e7133dca061ab6d5 @polotek committed Sep 16, 2012
Showing with 9 additions and 9 deletions.
  1. +5 −5 lib/route.js
  2. +4 −4 lib/router.js
View
@@ -40,7 +40,7 @@ Route.prototype.PARTS = /\([^)]+\)|:[a-zA-Z_][\w\-]*|\*[a-zA-Z_][\w\-]*|[\w\-_\\
//
Route.prototype.match = function( router, path, method, optional ){
- if ( typeof path != 'string' ) throw 'path must be a string'
+ if ( typeof path != 'string' ) throw new Error('path must be a string')
// is this a nested path?
if ( this.path != undefined ) {
@@ -216,7 +216,7 @@ Route.prototype.to = function( endpoint, extra_params ) {
if ( endpoint ){
endpoint = endpoint.split('.')
- if( kindof(endpoint) == 'array' && endpoint.length != 2 ) throw 'syntax should be in the form: controller.action'
+ if( kindof(endpoint) == 'array' && endpoint.length != 2 ) throw new Error('syntax should be in the form: controller.action')
this.params.controller = endpoint[0]
this.params.action = endpoint[1]
}
@@ -253,7 +253,7 @@ Route.prototype.name = function( name ) {
//
Route.prototype.where = function( conditions ) {
- if ( kindof(conditions) != 'object' ) throw 'conditions must be an object'
+ if ( kindof(conditions) != 'object' ) throw new Error('conditions must be an object')
for (var i in this.parts) {
if (this.parts[i] instanceof Key || this.parts[i] instanceof Route) {
@@ -439,7 +439,7 @@ Route.prototype.parse = function( urlParam, method ) {
Route.prototype.nest = function(cb){
- if ( typeof cb != 'function' ) throw 'route.nest() requires a callback function'
+ if ( typeof cb != 'function' ) throw new Error('route.nest() requires a callback function')
cb.call( this )
return this // for chaining
-}
+}
View
@@ -42,7 +42,7 @@ Router.prototype.match = function( path, method ) {
if ( typeof method == 'string' ) method = method.toUpperCase()
- if ( typeof method != 'undefined' && !this.methods_regexp().test(method)) throw 'method must be one of: ' + this.METHODS.join(', ')
+ if ( typeof method != 'undefined' && !this.methods_regexp().test(method)) throw new Error('method must be one of: ' + this.METHODS.join(', '))
var route = new Route( this, path, method)
// this.routes.push(route)
@@ -240,17 +240,17 @@ Router.prototype.methods_regexp = function(){
// **THIS IS CURRENTLY COMPLETELY UNTESTED. IT MIGHT NOT EVEN WORK. SERIOUSLY.**
//
Router.prototype.defer = function( fn ) {
- if ( typeof(fn) != 'function' ) throw 'Router.defer requires a function as the only argument'
+ if ( typeof(fn) != 'function' ) throw new Error('Router.defer requires a function as the only argument')
var route = new Route(this, 'deferred')
route.parse = fn // add the custom parser
delete route.test // = function(){return false};
- delete route.stringify //= function(){ throw 'Deferred routes are NOT generatable'};
+ delete route.stringify //= function(){ throw new Error('Deferred routes are NOT generatable')};
this.routes.push(route)
return route
}
Router.prototype.list = function(){
console.log(this.routes.map(function(rt){return rt.path}))
-}
+}

0 comments on commit 36130ad

Please sign in to comment.