Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TEACHING-MATERIALS/exercises/09_api_basics/bookshop/async/modules/errors.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
25 lines (21 sloc)
882 Bytes
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
/* Custom errors to throw from api modules */ | |
'use strict' | |
function error(name, default_message) { | |
function ErrorConstructor(message) { | |
this.name = name | |
this.message = message || default_message | |
this.stack = (new Error()).stack | |
} | |
ErrorConstructor.prototype = Object.create(Error.prototype) | |
ErrorConstructor.prototype.constructor = ErrorConstructor | |
return ErrorConstructor | |
} | |
module.exports = { | |
ItemExistsError: error('ItemExistsError', 'item exists already'), | |
NotFoundError: error('NotFoundError', 'item not found'), | |
ValidationError: error('ValidationError', 'invalid data'), | |
ConnectionError: error('ConnectionError', 'could not connect'), | |
ConfirmationError: error('ConfirmationError', 'confirmation code does not match'), | |
AuthorizationError: error('AuthorizationError', 'unauthorized'), | |
GatewayError: error('GatewayError', 'received an unexpected response') | |
} |