Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/api/user-setup.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getGraphQLErrors } from './graphql-errors.ts';

const USER_SETUP_MAX_ATTEMPTS = 3;
const USER_SETUP_RETRY_DELAY_MS = 500;
const USER_FACING_SERVER_ERROR = 'Please contact your administrator.';
const USER_FACING_SERVER_ERROR = 'Please contact support@herodevs.com.';
const SERVER_ERROR_CODES = ['INTERNAL_SERVER_ERROR', 'SERVER_ERROR', 'SERVICE_UNAVAILABLE'];

type UserSetupStatusData = { isComplete: boolean; orgId?: number | null };
Expand Down Expand Up @@ -116,5 +116,5 @@ export async function ensureUserSetup(): Promise<number> {
return result.orgId;
}

throw new Error('User setup did not return an organization ID. Please contact your administrator.');
throw new Error(`User setup did not return an organization ID. ${USER_FACING_SERVER_ERROR}`);
}
6 changes: 3 additions & 3 deletions src/commands/scan/eol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ export default class ScanEol extends Command {
}));

const errorMessages: Record<string, string> = {
SESSION_EXPIRED: 'Your session is no longer valid. To re-authenticate, run "hd auth login".',
INVALID_TOKEN: 'Your session is no longer valid. To re-authenticate, run "hd auth login".',
UNAUTHENTICATED: 'Please log in to perform a scan. To authenticate, run "hd auth login".',
SESSION_EXPIRED: 'Your session is no longer valid. To re-authenticate, please run an "auth login" command.',
INVALID_TOKEN: 'Your session is no longer valid. To re-authenticate, please run an "auth login" command.',
UNAUTHENTICATED: 'Please log in to perform a scan. To authenticate, please run an "auth login" command.',
FORBIDDEN: 'You do not have permission to perform this action.',
};
const message = errorMessages[error.code] ?? error.message?.trim();
Expand Down
12 changes: 9 additions & 3 deletions src/service/auth.svc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function getAccessToken(): Promise<string | undefined> {
export async function requireAccessToken(): Promise<string> {
const token = await getAccessToken();
if (!token) {
throw new Error('You are not logged in. Run "hd auth login" to authenticate.');
throw new Error('You are not logged in. Please run an "auth login" command to authenticate.');
}

return token;
Expand All @@ -68,7 +68,10 @@ export async function requireAccessTokenForScan(): Promise<string> {
const tokens = await getStoredTokens();

if (!tokens?.accessToken) {
throw new AuthError('Please log in to perform a scan. To authenticate, run "hd auth login".', 'NOT_LOGGED_IN');
throw new AuthError(
'Please log in to perform a scan. To authenticate, please run an "auth login" command.',
'NOT_LOGGED_IN',
);
}

if (!isAccessTokenExpired(tokens.accessToken)) {
Expand All @@ -85,5 +88,8 @@ export async function requireAccessTokenForScan(): Promise<string> {
}
}

throw new AuthError('Your session is no longer valid. To re-authenticate, run "hd auth login".', 'SESSION_EXPIRED');
throw new AuthError(
'Your session is no longer valid. To re-authenticate, please run an "auth login" command.',
'SESSION_EXPIRED',
);
}
2 changes: 1 addition & 1 deletion src/utils/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export async function withRetries<T>(operation: string, fn: () => Promise<T>, op
const message =
finalErrorMessage ??
(lastError instanceof Error ? lastError.message : null) ??
'Please contact your administrator.';
'Please contact support@herodevs.com.';
throw new Error(message);
}
2 changes: 1 addition & 1 deletion test/api/user-setup.client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('user-setup.client', () => {
{ message: 'Internal server error', extensions: { code: 'INTERNAL_SERVER_ERROR' } },
]);

await expect(ensureUserSetup()).rejects.toThrow('Please contact your administrator.');
await expect(ensureUserSetup()).rejects.toThrow('Please contact support@herodevs.com.');
expect(fetchMock.getCalls()).toHaveLength(3);
});
});
4 changes: 2 additions & 2 deletions test/service/auth.svc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('auth.svc', () => {
await expect(requireAccessTokenForScan()).rejects.toMatchObject({
name: 'AuthError',
code: 'NOT_LOGGED_IN',
message: 'Please log in to perform a scan. To authenticate, run "hd auth login".',
message: 'Please log in to perform a scan. To authenticate, please run an "auth login" command.',
});
});

Expand All @@ -206,7 +206,7 @@ describe('auth.svc', () => {
await expect(requireAccessTokenForScan()).rejects.toThrow(AuthError);
await expect(requireAccessTokenForScan()).rejects.toMatchObject({
code: 'SESSION_EXPIRED',
message: 'Your session is no longer valid. To re-authenticate, run "hd auth login".',
message: 'Your session is no longer valid. To re-authenticate, please run an "auth login" command.',
});
});

Expand Down