From 222109fc5a84b26eda285ef88e39b16c94d998e0 Mon Sep 17 00:00:00 2001 From: "ddejong@rpmmoves.com" Date: Wed, 25 Mar 2026 23:13:48 -0500 Subject: [PATCH] fix: surface Motion API error message on 404 responses Previously, all 404 errors showed a generic "The requested resource was not found" message, hiding the actual API response (e.g. "Unknown user schedule: Work Hours Plus"). Now 404s prefer the API message when available, making errors actionable. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/utils/errors.ts | 5 +++++ tests/unit/errors.test.ts | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 22cb3a9..3e4957e 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -263,6 +263,11 @@ function buildUserMessage( if (statusCode === 401 || statusCode === 403) { return `${STATUS_CODE_MESSAGES[statusCode]} Unable to ${action} ${resource}${resourceInfo}.`; } + // For 404s, prefer the API message when available (e.g. "Unknown user schedule: X") + // since it's more actionable than the generic "resource not found" + if (statusCode === 404 && apiMessage) { + return `Unable to ${action} ${resource}${resourceInfo}. ${apiMessage}`; + } return `Unable to ${action} ${resource}${resourceInfo}. ${STATUS_CODE_MESSAGES[statusCode]}`; } diff --git a/tests/unit/errors.test.ts b/tests/unit/errors.test.ts index 02d69ca..60c9321 100644 --- a/tests/unit/errors.test.ts +++ b/tests/unit/errors.test.ts @@ -328,8 +328,19 @@ describe('createErrorContext', () => { }); describe('createUserFacingError', () => { - it('creates error with user-friendly message for Axios 404', () => { - const axiosErr = fakeAxiosError(404); + it('creates error with user-friendly message for Axios 404 with API message', () => { + const axiosErr = fakeAxiosError(404, 'Unknown user schedule: Work Hours Plus'); + const ctx = createErrorContext('fetch', 'task', 'abc123'); + const err = createUserFacingError(axiosErr, ctx); + + expect(err).toBeInstanceOf(UserFacingError); + expect(err.userMessage).toContain('Unable to load task'); + expect(err.userMessage).toContain('Unknown user schedule: Work Hours Plus'); + expect(err.code).toBe(ERROR_CODES.RESOURCE_NOT_FOUND); + }); + + it('creates error with generic message for Axios 404 without API message', () => { + const axiosErr = fakeAxiosError(404, ''); const ctx = createErrorContext('fetch', 'task', 'abc123'); const err = createUserFacingError(axiosErr, ctx);