Skip to content

Commit

Permalink
Merge pull request #68 from linkedconnections/development
Browse files Browse the repository at this point in the history
v2.0.5
  • Loading branch information
julianrojas87 authored Nov 25, 2022
2 parents 658f694 + ae8685b commit 163d103
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
17 changes: 11 additions & 6 deletions lib/GtfsIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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 });
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions test/gtfsrt2lc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 163d103

Please sign in to comment.