UNPKG

pagaris

Version:

Pagaris API client for Node

39 lines (34 loc) 1.32 kB
const DEFAULT_MESSAGE = 'An unexpected error occurred when making a request' const DEFAULT_MESSAGES = { HTTPBaseError: DEFAULT_MESSAGE, ServerError: 'An internal server error occurred. Please try again.', UnauthorizedError: 'Your credentials may be incorrect (set them with ' + '`Pagaris.applicationId` and `Pagaris.privateKey`), or you may not ' + 'have access to perform this action.', NotFoundError: 'The requested resource could not be found', UnprocessableEntityError: 'Incorrectly formed request. Probably there is a '+ ' missing parameter or the request is somehow invalid. Check `response` '+ 'for details.', UnexpectedResponseError: DEFAULT_MESSAGE } class HTTPBaseError extends Error { constructor (response, message) { super(message) if (!message) this.message = DEFAULT_MESSAGES[this.constructor.name] this.name = this.constructor.name this.response = response } } class ServerError extends HTTPBaseError {} class UnauthorizedError extends HTTPBaseError {} class NotFoundError extends HTTPBaseError {} class UnprocessableEntityError extends HTTPBaseError {} class UnexpectedResponseError extends HTTPBaseError {} module.exports = { HTTPBaseError, ServerError, UnauthorizedError, NotFoundError, UnprocessableEntityError, UnexpectedResponseError };