From f5af0c8711d43fd079ba5131f60bf2eb57fd096c Mon Sep 17 00:00:00 2001 From: Johannes Heuel Date: Sat, 4 Mar 2023 20:41:32 +0100 Subject: [PATCH] check status code of upload request --- frontend/src/components/home.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/home.js b/frontend/src/components/home.js index 5502985..0143463 100644 --- a/frontend/src/components/home.js +++ b/frontend/src/components/home.js @@ -61,8 +61,7 @@ function read_file(file) { } export function upload_file(file, url) { - return new Promise(resolve => { - console.log("hi"); + return new Promise((resolve, reject) => { read_file(file).then((content) => { fetch(url, { method: 'PUT', @@ -71,8 +70,13 @@ export function upload_file(file, url) { 'Content-Type': 'multipart/form-data', }, body: new Blob([content], { type: file.type }), - }).then(response => resolve(response)); - }, - reject => console.log(reject)); + }).then((resp) => { + if (resp.status >= 200 && resp.status < 300) { + resolve(resp); + } else { + reject(resp); + } + }); + }).catch(error => reject(error)); }); }