Skip to content

Instantly share code, notes, and snippets.

@KieronWiltshire
Created June 30, 2015 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KieronWiltshire/57a6884a144b211c4258 to your computer and use it in GitHub Desktop.
Save KieronWiltshire/57a6884a144b211c4258 to your computer and use it in GitHub Desktop.
//
// My 'exceptions.js' file
//
var createError = require('create-error');
/**
* InvalidSubjectType exception
*
* This exception should be thrown if the subject type
* provided to the object constructor doesn't exist.
*/
exports.InvalidSubjectType = function(type) {
return createError('InvalidSubjectType', {
messages: [
"The subject type provided doesn't exist:",
type
]
});
};
//
// My 'subject.js' file
//
var exceptions = require('./exceptions.js');
/**
* A Permission Subject.
*
* @param id
* @param type
* @constructor
*/
function Subject (id, type) {
if (typeof type !== "string") throw exceptions.InvalidSubjectType(type);
this.id = id;
this.type = type;
/**
* Get the subject identifier.
*
* @returns {*}
*/
this.getId = function() {
return this.id;
}
/**
* Get the subject type.
*
* @returns {string|*}
*/
this.getType = function() {
return this.type;
}
}
new Subject(1, 1);
// The issue that I'm getting:
// http://puu.sh/iIMhr/b644ff3493.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment