fixed image upload

This commit is contained in:
2020-12-09 18:13:50 +01:00
parent e43fa02ead
commit 26fc0db44e
2 changed files with 18 additions and 5 deletions

View File

@@ -22,7 +22,7 @@ axios.interceptors.response.use(
}) })
resolve(response) resolve(response)
} }
throw error throw error;
}) })
}); });

View File

@@ -30,15 +30,28 @@ export default function ImageUpload(props) {
setLoading(false); setLoading(false);
}) })
.catch((error) => { .catch((error) => {
dispatch(notification("Błąd wysyłania. Sprawdź rozmiar pliku (max 3MB.)", "error")) if (error.response) {
if (error.response.status === 413) {
dispatch(notification("Błąd wysyłania. Sprawdź rozmiar pliku (max 2MB.)", "error"))
} else if (error.response.status === 401) {
dispatch(notification("Błąd wysyłania. Brak dostępu.", "error"))
} else {
dispatch(notification("Błąd wysyłania. Serwer odrzucił plik.", "error"))
}
setLoading(false); setLoading(false);
throw error; } else if (error.request) {
dispatch(notification("Błąd wysyłania. Brak odpowiedzi od serwera.", "error"))
setLoading(false);
} else {
dispatch(notification("Błąd wysyłania.", "error"))
setLoading(false);
}
}); });
}; };
let imagePreview = ( let imagePreview = (
<div className="image-preview"> <div className="image-preview">
{loading ? <CircularProgress /> : "Proszę wybrać obraz. (max. 3MB)"} {loading ? <CircularProgress /> : "Proszę wybrać obraz. (max. 2MB)"}
</div> </div>
); );
if (img) { if (img) {