[FIX] Command previews crashing when API returns an error (#2254)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Djorkaeff Alexandre 2020-07-08 13:42:49 -03:00 committed by GitHub
parent 5b3be4ef0b
commit e1153deb57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -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) => {