From 3b72a38197b1a1cff1c059ed5c55bf9f9d50569d Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 17 Aug 2020 19:30:20 +0300
Subject: fix: catch PollCreation errors and use Bluebird

---
 src/containers/PollCreation/PollCreation.tsx | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'src/containers/PollCreation/PollCreation.tsx')

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');
     }
   };
-- 
cgit v1.2.3

