Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`;
}

Expand Down
15 changes: 13 additions & 2 deletions tests/unit/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down