From acaeb70ffa5cd3dd0f9895371f2edd6dcc558974 Mon Sep 17 00:00:00 2001 From: pkupczyk <piotr.kupczyk@id.ethz.ch> Date: Sun, 22 Dec 2019 14:22:16 +0100 Subject: [PATCH] SSDM-7583 : ObjectTypeForm - show error stack trace in the error dialog + properly encode all parts of mailto href --- .../js/components/common/dialog/Dialog.jsx | 6 +- .../components/common/dialog/ErrorDialog.jsx | 65 +++++++++++++++---- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/openbis_ng_ui/src/js/components/common/dialog/Dialog.jsx b/openbis_ng_ui/src/js/components/common/dialog/Dialog.jsx index 4ab5730a722..a489844f0ae 100644 --- a/openbis_ng_ui/src/js/components/common/dialog/Dialog.jsx +++ b/openbis_ng_ui/src/js/components/common/dialog/Dialog.jsx @@ -16,9 +16,7 @@ const styles = theme => ({ zIndex: '20000 !important' }, actions: { - marginLeft: theme.spacing(2), - marginRight: theme.spacing(2), - marginBottom: theme.spacing(1) + margin: theme.spacing(1) } }) @@ -48,7 +46,7 @@ class DialogWindow extends React.Component { > <DialogTitle>{_.isFunction(title) ? title(this) : title}</DialogTitle> <DialogContent> - <DialogContentText> + <DialogContentText component='div'> {_.isFunction(content) ? content(this) : content} </DialogContentText> </DialogContent> diff --git a/openbis_ng_ui/src/js/components/common/dialog/ErrorDialog.jsx b/openbis_ng_ui/src/js/components/common/dialog/ErrorDialog.jsx index 50dedec2ce8..a8fc180ea44 100644 --- a/openbis_ng_ui/src/js/components/common/dialog/ErrorDialog.jsx +++ b/openbis_ng_ui/src/js/components/common/dialog/ErrorDialog.jsx @@ -21,19 +21,28 @@ class ErrorDialog extends React.Component { const { error, onClose } = this.props - const content = error && error.message ? error.message : error - return ( <Dialog open={!!error} onClose={onClose} title={'Error'} - content={content || ''} + content={this.renderContent()} actions={this.renderButtons()} /> ) } + renderContent() { + const message = this.getErrorMessage() + const stack = this.getErrorStack() + return ( + <div> + <div>{message}</div> + <pre>{stack}</pre> + </div> + ) + } + renderButtons() { const { onClose, classes } = this.props return ( @@ -59,32 +68,62 @@ class ErrorDialog extends React.Component { } getErrorMailtoHref() { + const message = this.getErrorMessage() + const stack = this.getErrorStack() + let report = 'agent: ' + navigator.userAgent + - '%0D%0A' + + '\n' + 'domain: ' + location.hostname + - '%0D%0A' + + '\n' + 'timestamp: ' + new Date() + - '%0D%0A' + + '\n' + 'href: ' + - location.href.replace(new RegExp('&', 'g'), ' - ') + - '%0D%0A' + + location.href + + '\n' + 'error: ' + - JSON.stringify(this.props.error) + (message ? message : '') + + '\n' + + 'stack: ' + + (stack ? stack : '') let href = 'mailto:' + profile.devEmail + - '?subject=openBIS Error Report [' + - location.hostname + - ']' + + '?subject=' + + encodeURIComponent('openBIS Error Report [' + location.hostname + ']') + '&body=' + - report + encodeURIComponent(report) + return href } + + getErrorMessage() { + const { error } = this.props + + if (error) { + if (error.message) { + return error.message + } else { + return error + } + } else { + return null + } + } + + getErrorStack() { + const { error } = this.props + + if (error && error.stack) { + return error.stack + } else { + return null + } + } } export default withStyles(styles)(ErrorDialog) -- GitLab