Skip to content

Commit

Permalink
fix(api-gateway): handle can't parse date: Cannot read property 'end'…
Browse files Browse the repository at this point in the history
… of undefined
  • Loading branch information
paveltiunov committed Jun 12, 2019
1 parent 65e4942 commit a61b0da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/cubejs-api-gateway/UserError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class UserError extends Error {}

module.exports = UserError;
4 changes: 4 additions & 0 deletions packages/cubejs-api-gateway/dateParser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const chrono = require('chrono-node');
const moment = require('moment');
const UserError = require('./UserError');

module.exports = (dateString) => {
let momentRange;
Expand Down Expand Up @@ -28,6 +29,9 @@ module.exports = (dateString) => {
momentRange = [yesterday, yesterday];
} else {
const results = chrono.parse(dateString);
if (!results) {
throw new UserError(`Can't parse date: '${dateString}'`);
}
momentRange = results[0].end ? [
results[0].start.moment(),
results[0].end.moment()
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Joi = require('joi');
const moment = require('moment');
const dateParser = require('./dateParser');

class UserError extends Error {}
const UserError = require('./UserError');

const toConfigMap = (metaConfig) => (
R.pipe(
Expand Down

0 comments on commit a61b0da

Please sign in to comment.