From e1153deb57cd891c67245fc32aa3ce499022b122 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Wed, 8 Jul 2020 13:42:49 -0300 Subject: [PATCH] [FIX] Command previews crashing when API returns an error (#2254) Co-authored-by: Diego Mello --- app/containers/MessageBox/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 43e23c8d..81a08c23 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -541,12 +541,14 @@ class MessageBox extends Component { setCommandPreview = async(command, name, params) => { const { rid } = this.props; try { - const { preview } = await RocketChat.getCommandPreview(name, rid, params); - this.setState({ commandPreview: preview.items, showCommandPreview: true, command }); + const { success, preview } = await RocketChat.getCommandPreview(name, rid, params); + if (success) { + return this.setState({ commandPreview: preview?.items, showCommandPreview: true, command }); + } } catch (e) { - this.setState({ commandPreview: [], showCommandPreview: true, command: {} }); log(e); } + this.setState({ commandPreview: [], showCommandPreview: true, command: {} }); } setInput = (text) => {