]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/helpers/utils/upload.ts
Add video filters to common video pages
[github/Chocobozzz/PeerTube.git] / client / src / app / helpers / utils / upload.ts
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 }