Skip to content
Merged
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
13 changes: 11 additions & 2 deletions backend/src/interceptors/timeout.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import { Messages } from '../exceptions/text/messages.js';

@Injectable()
export class TimeoutInterceptor implements NestInterceptor {
intercept(_context: ExecutionContext, next: CallHandler): Observable<any> {
const timeoutMs = process.env.NODE_ENV !== 'test' ? 15000 : 200000;
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const request = context.switchToHttp().getRequest();
const isAIEndpoint = request.url.includes('/ai/v2/request/');
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using string matching with includes() for route detection is fragile and may match unintended URLs. Consider using a more robust approach like checking the route path from the controller metadata or using a regular expression with word boundaries to ensure exact path matching.

Suggested change
const isAIEndpoint = request.url.includes('/ai/v2/request/');
const isAIEndpoint = /^\/ai\/v2\/request(\/|$)/.test(request.url);

Copilot uses AI. Check for mistakes.
const timeoutMs = isAIEndpoint
? process.env.NODE_ENV !== 'test'
? 300000
: 600000
: process.env.NODE_ENV !== 'test'
? 15000
: 200000;
Comment on lines +11 to +17
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested ternary operators make this logic difficult to read and maintain. Consider extracting timeout values into named constants (e.g., AI_TIMEOUT_PROD, AI_TIMEOUT_TEST) and using a more straightforward if-else structure or a lookup object.

Copilot uses AI. Check for mistakes.

return next.handle().pipe(
timeout(timeoutMs),
catchError((err) => {
Expand Down
Loading