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);