Reject upload when status code is faulty
This commit is contained in:
parent
da898c68e3
commit
02dd0c296c
@ -4,5 +4,5 @@ export * from "./findAll"
|
|||||||
export * from "./plural"
|
export * from "./plural"
|
||||||
export * from "./requestIdleCallback"
|
export * from "./requestIdleCallback"
|
||||||
export * from "./swapElements"
|
export * from "./swapElements"
|
||||||
export * from "./fetchWithProgress"
|
export * from "./uploadWithProgress"
|
||||||
export * from "./bytesHumanReadable"
|
export * from "./bytesHumanReadable"
|
@ -2,7 +2,13 @@ export function uploadWithProgress(url, options: RequestInit, onProgress: ((ev:
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let xhr = new XMLHttpRequest()
|
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
|
xhr.onerror = reject
|
||||||
|
|
||||||
if(onProgress && xhr.upload) {
|
if(onProgress && xhr.upload) {
|
Loading…
Reference in New Issue
Block a user