Skip to content

Commit a61b0da

Browse files
committed
fix(api-gateway): handle can't parse date: Cannot read property 'end' of undefined
1 parent 65e4942 commit a61b0da

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class UserError extends Error {}
2+
3+
module.exports = UserError;

packages/cubejs-api-gateway/dateParser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const chrono = require('chrono-node');
22
const moment = require('moment');
3+
const UserError = require('./UserError');
34

45
module.exports = (dateString) => {
56
let momentRange;
@@ -28,6 +29,9 @@ module.exports = (dateString) => {
2829
momentRange = [yesterday, yesterday];
2930
} else {
3031
const results = chrono.parse(dateString);
32+
if (!results) {
33+
throw new UserError(`Can't parse date: '${dateString}'`);
34+
}
3135
momentRange = results[0].end ? [
3236
results[0].start.moment(),
3337
results[0].end.moment()

packages/cubejs-api-gateway/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Joi = require('joi');
44
const moment = require('moment');
55
const dateParser = require('./dateParser');
66

7-
class UserError extends Error {}
7+
const UserError = require('./UserError');
88

99
const toConfigMap = (metaConfig) => (
1010
R.pipe(

0 commit comments

Comments
 (0)