UNPKG

@simpleapps-com/augur-api

Version:

TypeScript client library for Augur microservices API endpoints

102 lines 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RateLimitError = exports.NotFoundError = exports.AuthenticationError = exports.ValidationError = exports.AugurError = void 0; class AugurError extends Error { constructor(params) { super(params.message); this.name = 'AugurAPIError'; this.code = params.code; this.statusCode = params.statusCode; this.service = params.service; this.endpoint = params.endpoint; this.requestId = params.requestId; this.validationErrors = params.validationErrors; // Maintains proper stack trace for where our error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, AugurError); } } } exports.AugurError = AugurError; class ValidationError extends AugurError { constructor(params) { super({ ...params, code: 'VALIDATION_ERROR', statusCode: 400, }); } /** * Format validation errors into human-readable messages * @returns Array of formatted error messages */ getFormattedErrors() { if (!this.validationErrors) { return []; } return this.validationErrors.map(error => { const path = error.path.length > 0 ? error.path.join('.') : 'root'; return `${path}: ${error.message}`; }); } /** * Get detailed validation error information for debugging * @returns Object with detailed error information */ getDetailedErrors() { if (!this.validationErrors) { return []; } return this.validationErrors.map(error => ({ path: error.path.length > 0 ? error.path.join('.') : 'root', message: error.message, code: error.code, received: 'received' in error ? error.received : undefined, expected: 'expected' in error ? error.expected : undefined, })); } /** * Override toString to include formatted validation errors * @returns String representation with validation details */ toString() { const baseMessage = super.toString(); const formattedErrors = this.getFormattedErrors(); if (formattedErrors.length > 0) { return `${baseMessage}\nValidation errors:\n${formattedErrors.map(err => ` - ${err}`).join('\n')}`; } return baseMessage; } } exports.ValidationError = ValidationError; class AuthenticationError extends AugurError { constructor(params) { super({ ...params, code: 'AUTHENTICATION_ERROR', statusCode: 401, }); } } exports.AuthenticationError = AuthenticationError; class NotFoundError extends AugurError { constructor(params) { super({ ...params, code: 'NOT_FOUND', statusCode: 404, }); } } exports.NotFoundError = NotFoundError; class RateLimitError extends AugurError { constructor(params) { super({ ...params, code: 'RATE_LIMIT_EXCEEDED', statusCode: 429, }); } } exports.RateLimitError = RateLimitError; //# sourceMappingURL=errors.js.map