Created
February 8, 2018 04:04
-
-
Save CaptainLiao/7d0ee3e0a165b83f60a806428df0818b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const UnimplementedError = createErrorType('Unimplemented'); | |
const AuthError = createErrorType('AuthError'); | |
const ResponseError = createErrorType('ResponseError', function(message, data) { | |
this.data = data; | |
}); | |
module.exports = { | |
UnimplementedError, | |
AuthError, | |
ResponseError | |
}; | |
function createErrorType(name, init) { | |
function CustomError(message) { | |
this.message = message; | |
init && init.apply(this, arguments); | |
} | |
CustomError.prototype = Object.create(Error.prototype, { | |
name: { | |
value: name | |
}, | |
constructor: { | |
value: Error, | |
enumerable: false, | |
writable: true, | |
configurable: true | |
} | |
}); | |
if (Object.setPrototypeOf) { | |
Object.setPrototypeOf(CustomError, Error); | |
} else { | |
CustomError.__proto__ = Error; | |
} | |
return CustomError; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment