class AccountsAPIError extends Error { constructor(code, path, error, errorMessage) { super(errorMessage || error || "Accounts API Error") this.code = code this.path = path this.errorType = error this.errorMessage = errorMessage this.isOperational = true Error.captureStackTrace(this, this.constructor) } serialize() { const response = {} if (this.path && this.path.trim() !== "") { response.path = this.path.replace(/:(\w+)/g, "<$1>") } if (this.errorType && this.errorType.trim() !== "") { response.error = this.errorType } if (this.errorMessage && this.errorMessage.trim() !== "") { response.errorMessage = this.errorMessage } return response } } module.exports = AccountsAPIError