@grec0/mcp-s2s-asterisk
Version:
MCP server para asistente telefónico conversacional con Asterisk S2S
72 lines (71 loc) • 2.5 kB
JavaScript
export class PlankaError extends Error {
status;
response;
constructor(message, status, response) {
super(message);
this.status = status;
this.response = response;
this.name = "PlankaError";
}
}
export class PlankaValidationError extends PlankaError {
constructor(message, status, response) {
super(message, status, response);
this.name = "PlankaValidationError";
}
}
export class PlankaResourceNotFoundError extends PlankaError {
constructor(resource) {
super(`Resource not found: ${resource}`, 404, {
message: `${resource} not found`,
});
this.name = "PlankaResourceNotFoundError";
}
}
export class PlankaAuthenticationError extends PlankaError {
constructor(message = "Authentication failed") {
super(message, 401, { message });
this.name = "PlankaAuthenticationError";
}
}
export class PlankaPermissionError extends PlankaError {
constructor(message = "Insufficient permissions") {
super(message, 403, { message });
this.name = "PlankaPermissionError";
}
}
export class PlankaRateLimitError extends PlankaError {
resetAt;
constructor(message = "Rate limit exceeded", resetAt) {
super(message, 429, { message, reset_at: resetAt.toISOString() });
this.resetAt = resetAt;
this.name = "PlankaRateLimitError";
}
}
export class PlankaConflictError extends PlankaError {
constructor(message) {
super(message, 409, { message });
this.name = "PlankaConflictError";
}
}
export function isPlankaError(error) {
return error instanceof PlankaError;
}
export function createPlankaError(status, response) {
switch (status) {
case 401:
return new PlankaAuthenticationError(response?.message);
case 403:
return new PlankaPermissionError(response?.message);
case 404:
return new PlankaResourceNotFoundError(response?.message || "Resource");
case 409:
return new PlankaConflictError(response?.message || "Conflict occurred");
case 422:
return new PlankaValidationError(response?.message || "Validation failed", status, response);
case 429:
return new PlankaRateLimitError(response?.message, new Date(response?.reset_at || Date.now() + 60000));
default:
return new PlankaError(response?.message || "Planka API error", status, response);
}
}