diff options
Diffstat (limited to 'client/src/app/helpers/utils/upload.ts')
-rw-r--r-- | client/src/app/helpers/utils/upload.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/client/src/app/helpers/utils/upload.ts b/client/src/app/helpers/utils/upload.ts new file mode 100644 index 000000000..a3fce7fee --- /dev/null +++ b/client/src/app/helpers/utils/upload.ts | |||
@@ -0,0 +1,37 @@ | |||
1 | import { HttpErrorResponse } from '@angular/common/http' | ||
2 | import { Notifier } from '@app/core' | ||
3 | import { HttpStatusCode } from '@shared/models' | ||
4 | |||
5 | function genericUploadErrorHandler (parameters: { | ||
6 | err: Pick<HttpErrorResponse, 'message' | 'status' | 'headers'> | ||
7 | name: string | ||
8 | notifier: Notifier | ||
9 | sticky?: boolean | ||
10 | }) { | ||
11 | const { err, name, notifier, sticky } = { sticky: false, ...parameters } | ||
12 | const title = $localize`The upload failed` | ||
13 | let message = err.message | ||
14 | |||
15 | if (err instanceof ErrorEvent) { // network error | ||
16 | message = $localize`The connection was interrupted` | ||
17 | notifier.error(message, title, null, sticky) | ||
18 | } else if (err.status === HttpStatusCode.INTERNAL_SERVER_ERROR_500) { | ||
19 | message = $localize`The server encountered an error` | ||
20 | notifier.error(message, title, null, sticky) | ||
21 | } else if (err.status === HttpStatusCode.REQUEST_TIMEOUT_408) { | ||
22 | message = $localize`Your ${name} file couldn't be transferred before the set timeout (usually 10min)` | ||
23 | notifier.error(message, title, null, sticky) | ||
24 | } else if (err.status === HttpStatusCode.PAYLOAD_TOO_LARGE_413) { | ||
25 | const maxFileSize = err.headers?.get('X-File-Maximum-Size') || '8G' | ||
26 | message = $localize`Your ${name} file was too large (max. size: ${maxFileSize})` | ||
27 | notifier.error(message, title, null, sticky) | ||
28 | } else { | ||
29 | notifier.error(err.message, title) | ||
30 | } | ||
31 | |||
32 | return message | ||
33 | } | ||
34 | |||
35 | export { | ||
36 | genericUploadErrorHandler | ||
37 | } | ||