UNPKG

@felixgeelhaar/govee-api-client

Version:

Enterprise-grade TypeScript client library for the Govee Developer REST API

49 lines 2.12 kB
import { GoveeApiClientError } from './GoveeApiClientError'; export class NetworkError extends GoveeApiClientError { constructor(message, errorType = 'unknown', cause) { super(message, cause); this.code = 'NETWORK_ERROR'; this.errorType = errorType; } static fromAxiosError(error) { const message = error.message || 'Network request failed'; if (error.code === 'ECONNABORTED' || error.code === 'ETIMEDOUT') { return new NetworkError(`Request timeout: ${message}`, 'timeout', error); } if (error.code === 'ECONNREFUSED' || error.code === 'ECONNRESET' || error.code === 'ENOTFOUND') { return new NetworkError(`Connection failed: ${message}`, 'connection', error); } if (error.code === 'EAI_AGAIN') { return new NetworkError(`DNS resolution failed: ${message}`, 'dns', error); } if (error.code === 'ENOTFOUND') { return new NetworkError(`DNS resolution failed: ${message}`, 'dns', error); } return new NetworkError(`Network error: ${message}`, 'unknown', error); } isRetryable() { return this.errorType === 'timeout' || this.errorType === 'connection'; } getRecommendation() { switch (this.errorType) { case 'timeout': return 'The request timed out. Check your internet connection and consider increasing the timeout value.'; case 'connection': return 'Could not connect to the Govee API. Check your internet connection and verify the API is accessible.'; case 'dns': return 'Could not resolve the Govee API hostname. Check your DNS settings and internet connection.'; default: return 'A network error occurred. Check your internet connection and try again.'; } } toObject() { return { ...super.toObject(), errorType: this.errorType, recommendation: this.getRecommendation(), }; } } //# sourceMappingURL=NetworkError.js.map