@@ -2,6 +2,7 @@ import React, { Component } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import cx from 'classnames'
4
4
import contains from 'ramda/es/contains'
5
+ import { safeBooleanValue } from 'helpers'
5
6
6
7
import Text from './Text'
7
8
import Card from './Card'
@@ -14,6 +15,15 @@ import QuickReplies from './QuickReplies'
14
15
import './style.scss'
15
16
16
17
class 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
+
17
27
render ( ) {
18
28
const {
19
29
message,
@@ -37,16 +47,35 @@ class Message extends Component {
37
47
botMessageColor,
38
48
botMessageBackgroundColor,
39
49
} = 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
43
72
44
73
const image = isBot ? botPicture : userPicture
45
74
const messageProps = {
46
75
isBot,
47
76
// Make sure we display the title of a button/quickReply click, and not its value
48
77
content : title || content ,
49
- isMarkdown : markdown ,
78
+ isMarkdown : safeBooleanValue ( markdown ) ,
50
79
readOnlyMode,
51
80
onImageLoaded,
52
81
style : {
0 commit comments