fix: security hardening and performance improvements
Security: - Add token+secret auth to /setup-webhook and /webhook-info endpoints - Disable /api/test in production environment (ENVIRONMENT=production) Performance: - Add retryWithBackoff to weather-tool (maxRetries: 2) - Add KV caching to executeLookupDocs (1h TTL) Code Quality: - Centralize error messages in src/constants/messages.ts - Update 5 files to use centralized error constants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { CircuitBreaker, CircuitBreakerError } from './utils/circuit-breaker';
|
||||
import { createLogger } from './utils/logger';
|
||||
import { metrics } from './utils/metrics';
|
||||
import { getOpenAIUrl } from './utils/api-urls';
|
||||
import { ERROR_MESSAGES } from './constants/messages';
|
||||
|
||||
const logger = createLogger('openai');
|
||||
|
||||
@@ -175,17 +176,17 @@ export async function generateOpenAIResponse(
|
||||
// 에러 처리
|
||||
if (error instanceof CircuitBreakerError) {
|
||||
logger.error('Circuit breaker open', error as Error);
|
||||
return '죄송합니다. 일시적으로 서비스를 이용할 수 없습니다. 잠시 후 다시 시도해주세요.';
|
||||
return ERROR_MESSAGES.SERVICE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
if (error instanceof RetryError) {
|
||||
logger.error('All retry attempts failed', error as Error);
|
||||
return '죄송합니다. AI 응답 생성에 실패했습니다. 잠시 후 다시 시도해주세요.';
|
||||
return ERROR_MESSAGES.AI_RESPONSE_FAILED;
|
||||
}
|
||||
|
||||
// 기타 에러
|
||||
logger.error('Unexpected error', error as Error);
|
||||
return '죄송합니다. 예상치 못한 오류가 발생했습니다.';
|
||||
return ERROR_MESSAGES.UNEXPECTED_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,16 +217,16 @@ export async function generateProfileWithOpenAI(
|
||||
// 에러 처리
|
||||
if (error instanceof CircuitBreakerError) {
|
||||
logger.error('Profile - Circuit breaker open', error as Error);
|
||||
return '프로필 생성 실패: 일시적으로 서비스를 이용할 수 없습니다.';
|
||||
return ERROR_MESSAGES.PROFILE_GENERATION_FAILED;
|
||||
}
|
||||
|
||||
if (error instanceof RetryError) {
|
||||
logger.error('Profile - All retry attempts failed', error as Error);
|
||||
return '프로필 생성 실패: 재시도 횟수 초과';
|
||||
return ERROR_MESSAGES.PROFILE_GENERATION_FAILED;
|
||||
}
|
||||
|
||||
// 기타 에러
|
||||
logger.error('Profile - Unexpected error', error as Error);
|
||||
return '프로필 생성 실패: 예상치 못한 오류';
|
||||
return ERROR_MESSAGES.PROFILE_GENERATION_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user