First Commit - Portfolio Page

This commit is contained in:
2025-02-10 00:55:39 +01:00
commit bba0e331a8
239 changed files with 33355 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import { handleError, createAPIError } from './errorHandling';
interface RequestOptions extends RequestInit {
timeout?: number;
}
export async function fetchWithTimeout(
resource: string,
options: RequestOptions = {}
): Promise<Response> {
const { timeout = 8000, ...fetchOptions } = options;
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
try {
const response = await fetch(resource, {
...fetchOptions,
signal: controller.signal
});
if (!response.ok) {
throw createAPIError(
response.status,
`HTTP error! status: ${response.status}`
);
}
return response;
} catch (error) {
throw handleError(error, 'API Request');
} finally {
clearTimeout(id);
}
}