@felixgeelhaar/govee-api-client
Version:
Enterprise-grade TypeScript client library for the Govee Developer REST API
44 lines • 1.6 kB
JavaScript
import { GoveeApiClientError } from './GoveeApiClientError';
/**
* Error thrown when API response validation fails using Zod schemas
*/
export class ValidationError extends GoveeApiClientError {
constructor(message, zodError, rawData) {
super(message);
this.code = 'VALIDATION_ERROR';
this.name = 'ValidationError';
this.zodError = zodError;
this.rawData = rawData;
}
/**
* Create a ValidationError from a Zod validation failure
*/
static fromZodError(zodError, rawData) {
const errorMessages = zodError.issues.map(issue => {
const path = issue.path.length > 0 ? ` at path '${issue.path.join('.')}'` : '';
return `${issue.message}${path}`;
});
const message = `API response validation failed: ${errorMessages.join(', ')}`;
return new ValidationError(message, zodError, rawData);
}
/**
* Get a detailed breakdown of validation errors
*/
getValidationDetails() {
return this.zodError.issues.map(issue => ({
path: issue.path.join('.'),
message: issue.message,
received: issue.path.reduce((obj, key) => obj?.[key], this.rawData),
}));
}
/**
* Get a summary of validation errors for logging
*/
getValidationSummary() {
const details = this.getValidationDetails();
return details
.map(detail => `${detail.path}: ${detail.message} (received: ${JSON.stringify(detail.received)})`)
.join('; ');
}
}
//# sourceMappingURL=ValidationError.js.map