@stackbit/sdk
Version:
84 lines (77 loc) • 3.44 kB
text/typescript
export const REFER_TO_STACKBIT_REFERENCE_DOCS = 'please refer to Stackbit documentation: https://docs.stackbit.com/reference/';
export const REFER_TO_STACKBIT_CONFIG_DOCS = REFER_TO_STACKBIT_REFERENCE_DOCS + 'config';
export const STACKBIT_CONFIG_NOT_FOUND = `stackbit.yaml or stackbit.config.js was not found, ${REFER_TO_STACKBIT_CONFIG_DOCS}`;
export class ConfigLoadError extends Error {
name: 'ConfigLoadError';
originalError?: Error;
constructor(message: string, { originalError }: { originalError?: Error } = {}) {
super(message);
this.name = 'ConfigLoadError';
if (originalError) {
this.originalError = originalError;
this.stack = originalError.stack;
}
// redefine "message" as enumerable, this helps comparing the received and the expected error.message in Jest's toMatchObject() tests
Object.defineProperty(this, 'message', { value: message, writable: true, enumerable: true, configurable: true });
}
}
export class StackbitConfigNotFoundError extends Error {
name: 'StackbitConfigNotFoundError';
constructor() {
super(STACKBIT_CONFIG_NOT_FOUND);
this.name = 'StackbitConfigNotFoundError';
// redefine "message" as enumerable, this helps comparing the received and the expected error.message in Jest's toMatchObject() tests
Object.defineProperty(this, 'message', { value: STACKBIT_CONFIG_NOT_FOUND, writable: true, enumerable: true, configurable: true });
}
}
export class ModelLoadError extends Error {
name: 'ModelLoadError';
originalError?: Error;
constructor(message: string, { originalError }: { originalError?: Error } = {}) {
super(message);
this.name = 'ModelLoadError';
if (originalError) {
this.originalError = originalError;
this.stack = originalError.stack;
}
// redefine "message" as enumerable, this helps comparing the received and the expected error.message in Jest's toMatchObject() tests
Object.defineProperty(this, 'message', { value: message, writable: true, enumerable: true, configurable: true });
}
}
export class ConfigValidationError extends Error {
name: 'ConfigValidationError';
type: string;
fieldPath: (string | number)[];
normFieldPath: (string | number)[];
value?: any;
constructor({
message,
type,
fieldPath,
normFieldPath,
value
}: {
message: string;
type: string;
fieldPath: (string | number)[];
normFieldPath?: (string | number)[];
value?: any;
}) {
super(message);
this.name = 'ConfigValidationError';
this.type = type;
this.fieldPath = fieldPath;
this.normFieldPath = normFieldPath || fieldPath;
this.value = value;
// redefine "message" as enumerable, this helps comparing the received and the expected error.message in Jest's toMatchObject() tests
Object.defineProperty(this, 'message', { value: message, writable: true, enumerable: true, configurable: true });
}
}
export class ConfigPresetsError extends Error {
name: 'ConfigPresetsError';
constructor(message: string) {
super(message);
this.name = 'ConfigPresetsError';
}
}
export type ConfigError = ConfigLoadError | StackbitConfigNotFoundError | ModelLoadError | ConfigValidationError | ConfigPresetsError;