From 392d5917b716712f279908eada32f3f2965fdf11 Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Fri, 25 Nov 2022 18:29:25 +0100 Subject: [PATCH 1/3] Fix error handling bug when unzipping --- lib/GtfsIndex.js | 17 +++++++++++------ lib/Utils.js | 1 - 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/GtfsIndex.js b/lib/GtfsIndex.js index 710b595..d704ee7 100644 --- a/lib/GtfsIndex.js +++ b/lib/GtfsIndex.js @@ -48,12 +48,17 @@ class GtfsIndex { } async download(url, headers) { - const res = await request(url, { method: 'GET', headers }); + try { + const res = await request(url, { method: 'GET', headers }); - if (res.statusCode === 200) { - await this.unzip(await res.body); - } else { - throw new Error(`Error on HTTP request: ${url}, Message: ${await res.body.text()}`); + if (res.statusCode === 200) { + await this.unzip(await res.body); + } else { + throw new Error(`Error on HTTP request: ${url}, Message: ${await res.body.text()}`); + } + } catch (err) { + await this.cleanUp(); + throw err; } } @@ -295,7 +300,7 @@ class GtfsIndex { async cleanUp() { // We don't want to delete sources that are probably been reused - if(this.auxPath !== this.path) { + if (this.auxPath !== this.path) { await del([this.auxPath], { force: true }); } } diff --git a/lib/Utils.js b/lib/Utils.js index 0af5270..80eb4c4 100644 --- a/lib/Utils.js +++ b/lib/Utils.js @@ -9,7 +9,6 @@ function unzipStream(stream, outPath) { } stream.pipe(unzip.Extract({ path: outPath })) .on('error', async err => { - await this.cleanUp(); reject(err); }) .on('close', () => { From 1f0df8e59177ba41318081683a7a0065998dfd81 Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Fri, 25 Nov 2022 18:29:33 +0100 Subject: [PATCH 2/3] 2.0.5 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a07e813..af76f84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gtfsrt2lc", - "version": "2.0.4", + "version": "2.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gtfsrt2lc", - "version": "2.0.4", + "version": "2.0.5", "license": "MIT", "dependencies": { "commander": "^5.0.0", diff --git a/package.json b/package.json index c157a4d..24c1717 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gtfsrt2lc", - "version": "2.0.4", + "version": "2.0.5", "description": "Converts the GTFS-RT to Linked Connections", "main": "./Gtfsrt2LC.js", "bin": { From ae8685b63627045c4163e785ed2cd510ffe2af25 Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Fri, 25 Nov 2022 19:02:33 +0100 Subject: [PATCH 3/3] Increase test coverage --- test/gtfsrt2lc.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/gtfsrt2lc.test.js b/test/gtfsrt2lc.test.js index fd62951..c2c0a2e 100644 --- a/test/gtfsrt2lc.test.js +++ b/test/gtfsrt2lc.test.js @@ -583,6 +583,10 @@ test('Cover GtfsIndex functions', async () => { try { await gti.getIndexes(); } catch (err) { } + + try { + await gti.download('http://google.com'); + } catch (err) { } }); test('Cover Utils functions', async () => {