aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers/utils/upload.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-19 09:24:29 +0200
committerChocobozzz <me@florianbigard.com>2021-08-25 11:24:11 +0200
commitdd24f1bb0a4b252e5342b251ba36853364da7b8e (patch)
tree41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/helpers/utils/upload.ts
parent2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff)
downloadPeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz
PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst
PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip
Add video filters to common video pages
Diffstat (limited to 'client/src/app/helpers/utils/upload.ts')
-rw-r--r--client/src/app/helpers/utils/upload.ts37
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 @@
1import { HttpErrorResponse } from '@angular/common/http'
2import { Notifier } from '@app/core'
3import { HttpStatusCode } from '@shared/models'
4
5function 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
35export {
36 genericUploadErrorHandler
37}