Reject upload when status code is faulty

This commit is contained in:
Eduard Urbach 2018-11-21 20:45:15 +09:00
parent da898c68e3
commit 02dd0c296c
2 changed files with 8 additions and 2 deletions

View File

@ -4,5 +4,5 @@ export * from "./findAll"
export * from "./plural"
export * from "./requestIdleCallback"
export * from "./swapElements"
export * from "./fetchWithProgress"
export * from "./uploadWithProgress"
export * from "./bytesHumanReadable"

View File

@ -2,7 +2,13 @@ export function uploadWithProgress(url, options: RequestInit, onProgress: ((ev:
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest()
xhr.onload = e => resolve(xhr.responseText)
xhr.onload = () => {
if(xhr.status >= 400) {
return reject(xhr.responseText)
}
resolve(xhr.responseText)
}
xhr.onerror = reject
if(onProgress && xhr.upload) {