From ba9c272c207825b2f2943b1cb3da95f8b74ecae2 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Thu, 29 Jan 2026 21:23:35 -0600 Subject: [PATCH] fix: address code review feedback - Fix API endpoint paths: /events (not /api/events) to match actual NestJS routes - Convert script to ES modules (import/export) to match package.json type: module - Add detailed error messages for common HTTP status codes (401, 403, 404, 400) - Improve error handling with actionable guidance --- packages/skills/calendar/scripts/calendar.js | 37 +++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/skills/calendar/scripts/calendar.js b/packages/skills/calendar/scripts/calendar.js index c76346e..a7b3919 100755 --- a/packages/skills/calendar/scripts/calendar.js +++ b/packages/skills/calendar/scripts/calendar.js @@ -5,9 +5,9 @@ * Interacts with Mosaic Stack's Events API for calendar management */ -const https = require('https'); -const http = require('http'); -const { URL } = require('url'); +import https from 'https'; +import http from 'http'; +import { URL } from 'url'; // Configuration const API_URL = process.env.MOSAIC_API_URL || 'http://localhost:3001'; @@ -44,7 +44,20 @@ function apiRequest(method, path, body = null) { if (res.statusCode >= 200 && res.statusCode < 300) { resolve(parsed); } else { - reject(new Error(`HTTP ${res.statusCode}: ${parsed.message || data}`)); + // Provide helpful error messages based on status code + let errorMsg = `HTTP ${res.statusCode}: ${parsed.message || data}`; + + if (res.statusCode === 401) { + errorMsg += '\n → Check MOSAIC_API_TOKEN is valid'; + } else if (res.statusCode === 403) { + errorMsg += '\n → Verify workspace permissions and MOSAIC_WORKSPACE_ID'; + } else if (res.statusCode === 404) { + errorMsg += '\n → Resource not found. Check the event ID'; + } else if (res.statusCode === 400) { + errorMsg += '\n → Invalid request. Check date formats and required fields'; + } + + reject(new Error(errorMsg)); } } catch (err) { reject(new Error(`Failed to parse response: ${data}`)); @@ -105,7 +118,7 @@ async function createEvent(args) { if (args['project-id']) body.projectId = args['project-id']; if (args.metadata) body.metadata = JSON.parse(args.metadata); - const result = await apiRequest('POST', '/api/events', body); + const result = await apiRequest('POST', '/events', body); return result; } @@ -123,7 +136,7 @@ async function listEvents(args) { if (args.limit) params.append('limit', args.limit); const query = params.toString(); - const path = `/api/events${query ? '?' + query : ''}`; + const path = `/events${query ? '?' + query : ''}`; const result = await apiRequest('GET', path); return result; @@ -137,7 +150,7 @@ async function getEvent(eventId) { throw new Error('Event ID required'); } - const result = await apiRequest('GET', `/api/events/${eventId}`); + const result = await apiRequest('GET', `/events/${eventId}`); return result; } @@ -160,7 +173,7 @@ async function updateEvent(eventId, args) { if (args['project-id']) body.projectId = args['project-id']; if (args.metadata) body.metadata = JSON.parse(args.metadata); - const result = await apiRequest('PATCH', `/api/events/${eventId}`, body); + const result = await apiRequest('PATCH', `/events/${eventId}`, body); return result; } @@ -172,7 +185,7 @@ async function deleteEvent(eventId) { throw new Error('Event ID required'); } - const result = await apiRequest('DELETE', `/api/events/${eventId}`); + const result = await apiRequest('DELETE', `/events/${eventId}`); return result; } @@ -280,11 +293,9 @@ Environment: } // Run if called directly -if (require.main === module) { - main(); -} +main(); -module.exports = { +export { createEvent, listEvents, getEvent,