123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- export function getCurrentTimestampStr(): string {
- /**
- * Get the current timestamp as a string in the format yyyy-MM-dd HH:mm:ss
- * using local timezone.
- *
- * @returns Formatted datetime string in local time
- */
- return new Date()
- .toLocaleString('en-US', {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- second: '2-digit',
- hour12: false,
- })
- .replace(',', '');
- }
- /**
- * Checks if an error is related to API authentication
- *
- * @param error - The error to check
- * @returns boolean indicating if it's an authentication error
- */
- export function isAuthenticationError(error: unknown): boolean {
- if (!(error instanceof Error)) return false;
- // Get the error message
- const errorMessage = error.message || '';
- // Get error name - sometimes error.name just returns "Error" for custom errors
- let errorName = error.name || '';
- // Try to extract the constructor name, which often contains the actual error type
- // This works better than error.name for many custom errors
- const constructorName = error.constructor?.name;
- if (constructorName && constructorName !== 'Error') {
- errorName = constructorName;
- }
- // Check if the error name indicates an authentication error
- if (errorName === 'AuthenticationError') {
- return true;
- }
- // Fallback: check the message for authentication-related indicators
- return (
- errorMessage.toLowerCase().includes('authentication') ||
- errorMessage.includes('401') ||
- errorMessage.toLowerCase().includes('api key')
- );
- }
|