marketing-post-generator-mcp
Version:
A powerful MCP server for AI-powered marketing blog post generation with Claude integration
97 lines • 2.85 kB
JavaScript
// Base error class for the Marketing Post Generator MCP
export class BaseError extends Error {
context;
cause;
timestamp;
severity;
constructor(message, context, cause, severity = 'medium') {
super(message);
this.context = context;
this.cause = cause;
this.name = this.constructor.name;
this.timestamp = new Date().toISOString();
this.severity = severity;
Error.captureStackTrace(this, this.constructor);
}
toJSON() {
return {
name: this.name,
code: this.code,
message: this.message,
context: this.context,
stack: this.stack,
timestamp: this.timestamp,
severity: this.severity,
statusCode: this.statusCode,
};
}
withContext(additionalContext) {
const mergedContext = { ...this.context, ...additionalContext };
const ErrorConstructor = this.constructor;
const newError = new ErrorConstructor(this.message, mergedContext, this.cause, this.severity);
if (this.stack) {
newError.stack = this.stack;
}
return newError;
}
isRetryable() {
return this.statusCode >= 500 || this.statusCode === 429;
}
isUserError() {
return this.statusCode >= 400 && this.statusCode < 500 && this.statusCode !== 429;
}
isSystemError() {
return this.statusCode >= 500;
}
}
// Specific error types
export class ValidationError extends BaseError {
code = 'VALIDATION_ERROR';
statusCode = 400;
}
export class ContentGenerationError extends BaseError {
code = 'CONTENT_GENERATION_ERROR';
statusCode = 500;
}
export class StorageError extends BaseError {
code = 'STORAGE_ERROR';
statusCode = 500;
}
export class RateLimitError extends BaseError {
code = 'RATE_LIMIT_ERROR';
statusCode = 429;
}
export class ServiceUnavailableError extends BaseError {
code = 'SERVICE_UNAVAILABLE';
statusCode = 503;
}
export class ToolExecutionError extends BaseError {
toolName;
code = 'TOOL_EXECUTION_ERROR';
statusCode = 500;
constructor(message, toolName, cause) {
super(message, { toolName }, cause);
this.toolName = toolName;
}
}
export class NetworkError extends BaseError {
code = 'NETWORK_ERROR';
statusCode = 503;
}
export class TimeoutError extends BaseError {
code = 'TIMEOUT_ERROR';
statusCode = 504;
}
export class AuthenticationError extends BaseError {
code = 'AUTHENTICATION_ERROR';
statusCode = 401;
}
export class AuthorizationError extends BaseError {
code = 'AUTHORIZATION_ERROR';
statusCode = 403;
}
export class ConfigurationError extends BaseError {
code = 'CONFIGURATION_ERROR';
statusCode = 500;
}
//# sourceMappingURL=BaseError.js.map