content.teaser is not optional when Typescript is used
plankter opened this issue · 2 comments
plankter commented
If one does not provide content.teaser in getContent hook, then there is an exception:
stack":"TypeError: Cannot read property 'length' of
at Object.truncate (/app/node_modules/redis-notifications/lib/utils.js:135:14
at Object.default (/app/node_modules/redis-notifications/lib/schemas/message-content.js:32:22
at MessageContentSchema.module.exports.ObjSchema._validateKey (/app/node_modules/obj-schema/lib/main.js:157:33
at MessageContentSchema._validateKey (/app/node_modules/obj-schema/lib/main.js:5:59
at MessageContentSchema.module.exports.ObjSchema.validate (/app/node_modules/obj-schema/lib/main.js:123:21
at MessageContentSchema.validate (/app/node_modules/obj-schema/lib/main.js:5:59
at MessageContentSchema.module.exports.ObjSchema.validateCb (/app/node_modules/obj-schema/lib/main.js:86:19
at /app/node_modules/obj-schema/lib/main.js:5:
at /app/node_modules/redis-notifications/lib/tasks.js:181:
at RedisNotifications.NotificationManager.nf.on (/app/server/utils/NotificationManager.js:82:13
at emitMany (events.js:127:13
at RedisNotifications.emit (events.js:201:7
at RNTasks._getMessageContent (/app/node_modules/redis-notifications/lib/tasks.js:172:17
at RNTasks._getMessageContent (/app/node_modules/redis-notifications/lib/tasks.js:3:59
at /app/node_modules/redis-notifications/lib/tasks.js:77:17
it seems that the issue occurs due to the following code in "utils.coffee" file, where "str" argument expected to be defined:
@return { String } the truncated string
###
truncate: ( str, len = 100, add = "...", tolerance = 5 )->
if str.length > ( len * ( 1 + tolerance/100 ) )
return str.substr( 0, str.indexOf( " ", len ) ) + ( add or "" )
return str
plankter commented
Thanks!