@danielma-tic/mondaydotcom-mcp-server
Version:
MCP Server for the Monday.com API, enabling board operations, item management, and more.
49 lines (48 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotFoundError = exports.AuthenticationError = exports.ValidationError = exports.MondayError = void 0;
exports.handleMondayError = handleMondayError;
class MondayError extends Error {
constructor(message, statusCode, code) {
super(message);
this.statusCode = statusCode;
this.code = code;
this.name = 'MondayError';
}
}
exports.MondayError = MondayError;
class ValidationError extends Error {
constructor(message) {
super(message);
this.name = 'ValidationError';
}
}
exports.ValidationError = ValidationError;
class AuthenticationError extends Error {
constructor(message = 'Authentication failed') {
super(message);
this.name = 'AuthenticationError';
}
}
exports.AuthenticationError = AuthenticationError;
class NotFoundError extends Error {
constructor(resource) {
super(`${resource} not found`);
this.name = 'NotFoundError';
}
}
exports.NotFoundError = NotFoundError;
function handleMondayError(error) {
var _a, _b, _c, _d, _e;
if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errors) {
const apiError = error.response.data.errors[0];
throw new MondayError(apiError.message, error.response.status, apiError.code);
}
if (((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === 401) {
throw new AuthenticationError();
}
if (((_d = error.response) === null || _d === void 0 ? void 0 : _d.status) === 404) {
throw new NotFoundError('Resource');
}
throw new MondayError(error.message || 'An unexpected error occurred', (_e = error.response) === null || _e === void 0 ? void 0 : _e.status);
}