diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-17 19:30:20 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-17 19:30:20 +0300 |
commit | 3b72a38197b1a1cff1c059ed5c55bf9f9d50569d (patch) | |
tree | dde56a20e1a18b64cc93bc408981a65ee5f7a427 /src/containers/PollCreation/PollCreation.tsx | |
parent | 02ae366a22fa159a21aa531d539e4e034a31e271 (diff) | |
download | which-ui-3b72a38197b1a1cff1c059ed5c55bf9f9d50569d.tar.gz |
fix: catch PollCreation errors and use Bluebird
Diffstat (limited to 'src/containers/PollCreation/PollCreation.tsx')
-rw-r--r-- | src/containers/PollCreation/PollCreation.tsx | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index 107314a..489c12a 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import Bluebird from 'bluebird'; import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { @@ -49,21 +50,22 @@ const PollCreation: React.FC = () => { } = useS3Preupload(); const handleClick = async () => { - if (isLeftReady && isRightReady) { - const [leftUrl, rightUrl] = await Promise.all([resolveLeft(), resolveRight()]); + try { + const [leftUrl, rightUrl] = await Bluebird.all([resolveLeft(), resolveRight()]); const contents = { left: { url: leftUrl }, right: { url: rightUrl } }; + history.push('/feed'); + post('/polls/', { contents }).then(() => { updateFeed(); - enqueueSnackbar('Your poll has been successfully created!', { - variant: 'success' - }); + enqueueSnackbar('Your poll has been successfully created!', { variant: 'success' }); }); - + } catch (error) { + enqueueSnackbar('Failed to create a poll. Please, try again.', { variant: 'error' }); history.push('/feed'); } }; |