Skip to content

Commit faec03d

Browse files
committed
Clean up testing code in HTTP client
1 parent 51238da commit faec03d

2 files changed

Lines changed: 11 additions & 24 deletions

File tree

services/http.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@ export abstract class BaseHttpClient {
5151
return this._send(url, 'DELETE', undefined, config);
5252
}
5353

54-
async _sendTest(url: string, method: string, body?: HttpBody): Promise<Response> {
55-
const response = await fetch(this.url(url), {
56-
method,
57-
body,
58-
headers: {
59-
'Accept': 'application/text',
60-
'Authorization': this._requestHeaders.Authorization
61-
}
62-
});
63-
64-
if (!response.ok) {
65-
throw new BaseHttpClientError(response);
66-
}
67-
68-
return response;
69-
}
70-
7154
async _send(
7255
url: string,
7356
method: string,

services/tdei.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,17 @@ export class TdeiClient extends BaseHttpClient implements ICancelableClient {
242242
}
243243

244244
async downloadOswDataset(tdeiRecordId: string, format: string = 'osw'): Promise<Blob> {
245-
const response = await this._sendTest(`osw/${tdeiRecordId}?format=${format}`, 'GET');
245+
const response = await this._get(`osw/${tdeiRecordId}?format=${format}`, {
246+
headers: { Accept: '*/*' },
247+
});
246248

247249
return (await response.blob());
248250
}
249251

250252
async downloadPathwaysDataset(tdeiDatasetId: string): Promise<Blob> {
251-
const response = await this._sendTest(`gtfs-pathways/${tdeiDatasetId}`, 'GET');
253+
const response = await this._get(`gtfs-pathways/${tdeiDatasetId}`, {
254+
headers: { Accept: '*/*' },
255+
});
252256

253257
return (await response.blob());
254258
}
@@ -328,16 +332,14 @@ export class TdeiClient extends BaseHttpClient implements ICancelableClient {
328332
const filename = sourceFormat === 'osw' ? 'osw.zip' : 'osm.xml';
329333
body.append('file', new File([dataset], filename));
330334

331-
const jobResponse = await this._sendTest('osw/convert', 'POST', body);
335+
const jobResponse = await this._post('osw/convert', body);
332336
const jobId = (await jobResponse.text());
333337

334338
while (true) {
335339
console.info(`Waiting for dataset conversion job ${jobId}...`);
336340
await new Promise(resolve => setTimeout(resolve, 4000));
337341

338-
const statusResponse = await this._get(`jobs?job_id=${jobId}&tdei_project_group_id=${projectGroupId}`, {
339-
headers: { 'Accept': 'application/text' }
340-
});
342+
const statusResponse = await this._get(`jobs?job_id=${jobId}&tdei_project_group_id=${projectGroupId}`);
341343
const statusBody = (await statusResponse.json())[0];
342344
const statusText = statusBody.status.toLowerCase();
343345

@@ -350,7 +352,9 @@ export class TdeiClient extends BaseHttpClient implements ICancelableClient {
350352
}
351353
}
352354

353-
const fileResponse = await this._sendTest(`job/download/${jobId}`, 'GET');
355+
const fileResponse = await this._get(`job/download/${jobId}`, {
356+
headers: { 'Accept': '*/*' },
357+
});
354358

355359
return await fileResponse.blob();
356360
}

0 commit comments

Comments
 (0)