fix: switch from URL objects to strings

This commit is contained in:
gauthier-th
2024-06-29 01:49:07 +02:00
committed by Gauthier
parent 15568b1f6b
commit 6bcaa672ad
4 changed files with 33 additions and 29 deletions

View File

@@ -224,18 +224,17 @@ class ExternalAPI {
endpoint: string,
params?: Record<string, string>,
overwriteBaseUrl?: string
): URL {
): string {
const baseUrl = overwriteBaseUrl || this.baseUrl;
const href =
baseUrl +
(baseUrl.endsWith('/') ? '' : '/') +
(endpoint.startsWith('/') ? endpoint.slice(1) : endpoint);
const url = new URL(href);
url.search = new URLSearchParams({
const searchParams = new URLSearchParams({
...this.params,
...params,
}).toString();
return url;
});
return `${href}?${searchParams.toString()}`;
}
private serializeCacheKey(
@@ -249,7 +248,7 @@ class ExternalAPI {
return `${this.baseUrl}${endpoint}${JSON.stringify(params)}`;
}
private async getDataFromResponse(response: Response): Promise<any> {
private async getDataFromResponse(response: Response) {
const contentType = response.headers.get('Content-Type')?.split(';')[0];
if (contentType === 'application/json') {
return await response.json();