-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@uppy/xhr-upload: allow custom error message in onAfterResponse #5578
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Diff output filesdiff --git a/packages/@uppy/utils/lib/fetcher.js b/packages/@uppy/utils/lib/fetcher.js
index c273c2c..bcacbe2 100644
--- a/packages/@uppy/utils/lib/fetcher.js
+++ b/packages/@uppy/utils/lib/fetcher.js
@@ -28,6 +28,16 @@ export function fetcher(url, options) {
}
return new Promise(async (resolve, reject) => {
const xhr = new XMLHttpRequest();
+ const onError = error => {
+ if (shouldRetry(xhr) && retryCount < retries) {
+ setTimeout(() => {
+ requestWithRetry(retryCount + 1).then(resolve, reject);
+ }, delay(retryCount));
+ } else {
+ timer.done();
+ reject(error);
+ }
+ };
xhr.open(method, url, true);
xhr.withCredentials = withCredentials;
if (responseType) {
@@ -38,7 +48,13 @@ export function fetcher(url, options) {
reject(new DOMException("Aborted", "AbortError"));
});
xhr.onload = async () => {
- await onAfterResponse(xhr, retryCount);
+ try {
+ await onAfterResponse(xhr, retryCount);
+ } catch (err) {
+ err.request = xhr;
+ onError(err);
+ return;
+ }
if (xhr.status >= 200 && xhr.status < 300) {
timer.done();
resolve(xhr);
@@ -51,16 +67,7 @@ export function fetcher(url, options) {
reject(new NetworkError(xhr.statusText, xhr));
}
};
- xhr.onerror = () => {
- if (shouldRetry(xhr) && retryCount < retries) {
- setTimeout(() => {
- requestWithRetry(retryCount + 1).then(resolve, reject);
- }, delay(retryCount));
- } else {
- timer.done();
- reject(new NetworkError(xhr.statusText, xhr));
- }
- };
+ xhr.onerror = () => onError(new NetworkError(xhr.statusText, xhr));
xhr.upload.onprogress = event => {
timer.progress();
onUploadProgress(event);
diff --git a/packages/@uppy/xhr-upload/lib/index.js b/packages/@uppy/xhr-upload/lib/index.js
index fd18a3d..323b88e 100644
--- a/packages/@uppy/xhr-upload/lib/index.js
+++ b/packages/@uppy/xhr-upload/lib/index.js
@@ -202,11 +202,9 @@ export default class XHRUpload extends BasePlugin {
if (error.name === "AbortError") {
return undefined;
}
- if (error instanceof NetworkError) {
- const request = error.request;
- for (const file of files) {
- this.uppy.emit("upload-error", this.uppy.getFile(file.id), buildResponseError(request, error), request);
- }
+ const request = error.request;
+ for (const file of files) {
+ this.uppy.emit("upload-error", this.uppy.getFile(file.id), buildResponseError(request, error), request);
}
throw error;
} |
Murderlon
force-pushed
the
xhr-custom-error
branch
from
January 7, 2025 13:30
f67e9de
to
f2ab018
Compare
Thank you for the prompt response! I will test it as soon as possible |
Not released yet but soon |
github-actions bot
added a commit
that referenced
this pull request
Jan 8, 2025
| Package | Version | Package | Version | | -------------------------- | ------- | -------------------------- | ------- | | @uppy/google-drive-picker | 0.3.1 | @uppy/unsplash | 4.3.0 | | @uppy/google-photos-picker | 0.3.1 | @uppy/utils | 6.1.1 | | @uppy/onedrive | 4.2.1 | @uppy/xhr-upload | 4.3.1 | | @uppy/provider-views | 4.4.0 | uppy | 4.12.0 | | @uppy/svelte | 4.3.0 | | | - @uppy/unsplash,@uppy/provider-views: add utmSource option (Merlijn Vos / #5580) - @uppy/xhr-upload: allow custom error message in onAfterResponse (Merlijn Vos / #5578) - @uppy/onedrive: fix AsyncStore import (Merlijn Vos / #5579) - @uppy/google-drive-picker,@uppy/google-photos-picker: Fix Google Picker plugins locale (Merlijn Vos / #5575)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #5570