@@ -2,6 +2,7 @@ import React, { Component } from 'react'
22import PropTypes from 'prop-types'
33import cx from 'classnames'
44import contains from 'ramda/es/contains'
5+ import { safeBooleanValue } from 'helpers'
56
67import Text from './Text'
78import Card from './Card'
@@ -14,6 +15,15 @@ import QuickReplies from './QuickReplies'
1415import './style.scss'
1516
1617class Message extends Component {
18+ state = {
19+ exceptionThrownOccurred : false ,
20+ }
21+
22+ componentDidCatch ( error , info ) {
23+ this . setState ( { exceptionThrownOccurred : true } )
24+ console . error ( error , info )
25+ }
26+
1727 render ( ) {
1828 const {
1929 message,
@@ -37,16 +47,35 @@ class Message extends Component {
3747 botMessageColor,
3848 botMessageBackgroundColor,
3949 } = preferences
40- const { displayIcon } = message
41- const { type, content, error, title, markdown } = message . attachment
42- const isBot = message . participant . isBot
50+ const { displayIcon, attachment, participant } = message
51+ const { type, content, error, title, markdown } = attachment
52+ const { exceptionThrownOccurred } = this . state
53+ if ( exceptionThrownOccurred ) {
54+ const style = {
55+ color : '#fff' ,
56+ backgroundColor : '#f44336' ,
57+ padding : '1.0rem' ,
58+ textAlign : 'center' ,
59+ }
60+
61+ return (
62+ < div style = { style } className = { 'RecastAppText CaiAppText' } >
63+ An Error has occured, unable to display this message
64+ </ div >
65+ )
66+ }
67+ if ( ! content ) {
68+ console . error ( 'Missing content unable to proceed' )
69+ return null
70+ }
71+ const { isBot } = participant
4372
4473 const image = isBot ? botPicture : userPicture
4574 const messageProps = {
4675 isBot,
4776 // Make sure we display the title of a button/quickReply click, and not its value
4877 content : title || content ,
49- isMarkdown : markdown ,
78+ isMarkdown : safeBooleanValue ( markdown ) ,
5079 readOnlyMode,
5180 onImageLoaded,
5281 style : {
0 commit comments