Skip to content

Commit

Permalink
fix: Reject xhr only on errors (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 authored Sep 11, 2024
1 parent 8beebc7 commit 7ad8636
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/uploaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ export class XHRUploader extends AsyncUploader {
if (xhr.readyState !== 4) return;

// Process the response
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr as unknown as Response);
} else {
reject(xhr);
}
// We resolve all xhr responses whose ready state is 4 regardless of HTTP codes that may be errors (400+)
// because these are valid HTTP responses.
resolve((xhr as unknown) as Response);
};

// Reject a promise only when there is an xhr error
xhr.onerror = () => {
reject((xhr as unknown) as Response);
};


xhr.open(method, url);
xhr.send(data);
});
Expand Down

0 comments on commit 7ad8636

Please sign in to comment.