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 "./requestIdleCallback"
|
||||
export * from "./swapElements"
|
||||
export * from "./fetchWithProgress"
|
||||
export * from "./uploadWithProgress"
|
||||
export * from "./bytesHumanReadable"
|
@ -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) {
|
Loading…
Reference in New Issue
Block a user