From aa04667c4e55776cf5f965a223ecd61fcc6b1795 Mon Sep 17 00:00:00 2001 From: Joni Laukka <joni.laukka.overflow@gmail.com> Date: Thu, 11 Jul 2019 09:35:15 +0300 Subject: [PATCH] Edit form closes when submitted --- src/components/EditGameForm.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/EditGameForm.js b/src/components/EditGameForm.js index 88c4fa0..55247e6 100644 --- a/src/components/EditGameForm.js +++ b/src/components/EditGameForm.js @@ -258,12 +258,16 @@ export class EditGameForm extends React.Component { }, body: JSON.stringify(gameObject) }) - .then(res => res.json()) + .then(res => { + if (!res.ok) { + throw Error(res.statusMessage); + } else { + return res.json(); + } + }) .then(result => { alert(result.message); - if (result.code === 200) { - this.handleView(); - } + this.handleView(); }) .catch(error => console.log("Error: ", error)); }; -- GitLab