1 import { HttpErrorResponse } from '@angular/common/http'
2 import { Notifier } from '@app/core'
3 import { HttpStatusCode } from '@shared/models'
5 function genericUploadErrorHandler (options: {
6 err: Pick<HttpErrorResponse, 'message' | 'status' | 'headers'>
11 const { err, name, notifier, sticky = false } = options
12 const title = $localize`Upload failed`
13 const message = buildMessage(name, err)
15 notifier.error(message, title, null, sticky)
20 genericUploadErrorHandler
23 // ---------------------------------------------------------------------------
25 function buildMessage (name: string, err: Pick<HttpErrorResponse, 'message' | 'status' | 'headers'>) {
26 if (err instanceof ErrorEvent) { // network error
27 return $localize`The connection was interrupted`
30 if (err.status === HttpStatusCode.INTERNAL_SERVER_ERROR_500) {
31 return $localize`The server encountered an error`
34 if (err.status === HttpStatusCode.REQUEST_TIMEOUT_408) {
35 return $localize`Your ${name} file couldn't be transferred before the server proxy timeout`
38 if (err.status === HttpStatusCode.PAYLOAD_TOO_LARGE_413) {
39 const maxFileSize = err.headers?.get('X-File-Maximum-Size') || '8G'
40 return $localize`Your ${name} file was too large (max. size: ${maxFileSize})`