backend: implement request timeout handling for webhook requests

This commit is contained in:
juancarmore 2025-09-09 12:02:40 +02:00
parent f8ba8bd0d1
commit 22e2f1f046

View File

@ -208,11 +208,31 @@ export class OpenViduWebhookService {
}
protected async sendRequest(url: string, options: RequestInit): Promise<void> {
const response = await fetch(url, options);
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 seconds timeout
try {
const response = await fetch(url, {
...options,
signal: controller.signal
});
clearTimeout(timeoutId);
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}
} catch (error: any) {
clearTimeout(timeoutId);
// Handle timeout error specifically
if (error.name === 'AbortError') {
throw new Error('Request timed out after 5 seconds');
}
// Re-throw other errors
throw error;
}
}
/**
@ -223,7 +243,7 @@ export class OpenViduWebhookService {
*/
protected async sendTestRequest(url: string, options: RequestInit): Promise<void> {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 seconds timeout
try {
const response = await fetch(url, {
@ -258,7 +278,7 @@ export class OpenViduWebhookService {
let reason: string;
if (error.name === 'AbortError') {
reason = 'Request timed out after 10 seconds';
reason = 'Request timed out after 5 seconds';
} else if (error.name === 'TypeError' && error.message.includes('fetch')) {
// Network errors
const errorCode = error.cause?.code;