Skip to content

Commit

Permalink
Catch the error code while reading the config file in api
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentao-Kuang committed Sep 24, 2023
1 parent 32b98e2 commit 8155592
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 13 additions & 0 deletions packages/lambda-tiler/src/util/__test__/config.loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,17 @@ o.spec('ConfigLoader', () => {

o(await provider.Imagery.get('topographic')).deepEquals(await expectedConfig.Imagery.get('topographic'));
});

const deletedLocation = 'memory://linz-basemaps/config-deleted.json';
o('should Error 404 if config file not exists', async () => {
const error = await ConfigLoader.load(
mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=${deletedLocation}`, Api.header),
)
.then(() => null)
.catch((e) => e);

o(error instanceof LambdaHttpResponse).equals(true);
o((error as LambdaHttpResponse).status).equals(404);
o((error as LambdaHttpResponse).statusDescription).equals(`Config not found at ${deletedLocation}`);
});
});
14 changes: 9 additions & 5 deletions packages/lambda-tiler/src/util/config.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ export class ConfigLoader {

req.set('config', configLocation);
req.timer.start('config:load');
return CachedConfig.get(configLocation).then((f) => {
req.timer.end('config:load');
if (f == null) throw new LambdaHttpResponse(404, `Config not found at ${configLocation}`);
return f;
});
return CachedConfig.get(configLocation)
.then((f) => {
req.timer.end('config:load');
if (f == null) throw new LambdaHttpResponse(404, `Config not found at ${configLocation}`);
return f;
})
.catch((e) => {
throw new LambdaHttpResponse(e.status, e.statusDescription);
});
}
}

0 comments on commit 8155592

Please sign in to comment.