Skip to content

Commit 2a2018b

Browse files
author
Your Name
committed
@uppy/xhr-upload: add translatable networkError message (#6111)
The NetworkError class had a hardcoded error message that could not be translated via Uppy's i18n system. This adds a `networkError` locale key to @uppy/xhr-upload and threads the translated message through `buildResponseError` into the NetworkError constructor (which now accepts an optional `message` parameter).
1 parent 23cbd4a commit 2a2018b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/@uppy/utils/src/NetworkError.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ class NetworkError extends Error {
55

66
public request: null | XMLHttpRequest
77

8-
constructor(error: unknown, xhr: null | XMLHttpRequest = null) {
8+
constructor(
9+
error: unknown,
10+
xhr: null | XMLHttpRequest = null,
11+
message?: string,
12+
) {
913
super(
10-
`This looks like a network error, the endpoint might be blocked by an internet provider or a firewall.`,
14+
message ??
15+
`This looks like a network error, the endpoint might be blocked by an internet provider or a firewall.`,
1116
)
1217

1318
this.cause = error

packages/@uppy/xhr-upload/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ declare module '@uppy/core' {
9494
function buildResponseError(
9595
xhr?: XMLHttpRequest,
9696
err?: string | Error | NetworkError,
97+
networkErrorMessage?: string,
9798
) {
9899
let error = err
99100
// No error message
@@ -106,7 +107,7 @@ function buildResponseError(
106107
}
107108

108109
if (isNetworkError(xhr)) {
109-
error = new NetworkError(error, xhr)
110+
error = new NetworkError(error, xhr, networkErrorMessage)
110111
return error
111112
}
112113

@@ -276,7 +277,7 @@ export default class XHRUpload<
276277
this.uppy.emit(
277278
'upload-error',
278279
this.uppy.getFile(file.id),
279-
buildResponseError(request, error),
280+
buildResponseError(request, error, this.i18n('networkError')),
280281
request,
281282
)
282283
}

packages/@uppy/xhr-upload/src/locale.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ export default {
33
// Shown in the Informer if an upload is being canceled because it stalled for too long.
44
uploadStalled:
55
'Upload has not made any progress for %{seconds} seconds. You may want to retry it.',
6+
// Shown in the Dashboard when a network error occurs during upload.
7+
networkError:
8+
'This looks like a network error, the endpoint might be blocked by an internet provider or a firewall.',
69
},
710
}

0 commit comments

Comments
 (0)