Skip to content

Commit 163d103

Browse files
Merge pull request #68 from linkedconnections/development
v2.0.5
2 parents 658f694 + ae8685b commit 163d103

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

lib/GtfsIndex.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ class GtfsIndex {
4848
}
4949

5050
async download(url, headers) {
51-
const res = await request(url, { method: 'GET', headers });
51+
try {
52+
const res = await request(url, { method: 'GET', headers });
5253

53-
if (res.statusCode === 200) {
54-
await this.unzip(await res.body);
55-
} else {
56-
throw new Error(`Error on HTTP request: ${url}, Message: ${await res.body.text()}`);
54+
if (res.statusCode === 200) {
55+
await this.unzip(await res.body);
56+
} else {
57+
throw new Error(`Error on HTTP request: ${url}, Message: ${await res.body.text()}`);
58+
}
59+
} catch (err) {
60+
await this.cleanUp();
61+
throw err;
5762
}
5863
}
5964

@@ -295,7 +300,7 @@ class GtfsIndex {
295300

296301
async cleanUp() {
297302
// We don't want to delete sources that are probably been reused
298-
if(this.auxPath !== this.path) {
303+
if (this.auxPath !== this.path) {
299304
await del([this.auxPath], { force: true });
300305
}
301306
}

lib/Utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function unzipStream(stream, outPath) {
99
}
1010
stream.pipe(unzip.Extract({ path: outPath }))
1111
.on('error', async err => {
12-
await this.cleanUp();
1312
reject(err);
1413
})
1514
.on('close', () => {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gtfsrt2lc",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "Converts the GTFS-RT to Linked Connections",
55
"main": "./Gtfsrt2LC.js",
66
"bin": {

test/gtfsrt2lc.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ test('Cover GtfsIndex functions', async () => {
583583
try {
584584
await gti.getIndexes();
585585
} catch (err) { }
586+
587+
try {
588+
await gti.download('http://google.com');
589+
} catch (err) { }
586590
});
587591

588592
test('Cover Utils functions', async () => {

0 commit comments

Comments
 (0)