diff options
Diffstat (limited to 'client/src/app/helpers/utils.ts')
-rw-r--r-- | client/src/app/helpers/utils.ts | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/client/src/app/helpers/utils.ts b/client/src/app/helpers/utils.ts index 9c805b4ca..f96f26fff 100644 --- a/client/src/app/helpers/utils.ts +++ b/client/src/app/helpers/utils.ts | |||
@@ -1,7 +1,10 @@ | |||
1 | import { DatePipe } from '@angular/common' | 1 | import { DatePipe } from '@angular/common' |
2 | import { HttpErrorResponse } from '@angular/common/http' | ||
3 | import { Notifier } from '@app/core' | ||
2 | import { SelectChannelItem } from '@app/shared/shared-forms' | 4 | import { SelectChannelItem } from '@app/shared/shared-forms' |
3 | import { environment } from '../../environments/environment' | 5 | import { environment } from '../../environments/environment' |
4 | import { AuthService } from '../core/auth' | 6 | import { AuthService } from '../core/auth' |
7 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
5 | 8 | ||
6 | // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript | 9 | // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript |
7 | function getParameterByName (name: string, url: string) { | 10 | function getParameterByName (name: string, url: string) { |
@@ -172,6 +175,33 @@ function isXPercentInViewport (el: HTMLElement, percentVisible: number) { | |||
172 | ) | 175 | ) |
173 | } | 176 | } |
174 | 177 | ||
178 | function uploadErrorHandler (parameters: { | ||
179 | err: HttpErrorResponse | ||
180 | name: string | ||
181 | notifier: Notifier | ||
182 | sticky?: boolean | ||
183 | }) { | ||
184 | const { err, name, notifier, sticky } = { sticky: false, ...parameters } | ||
185 | const title = $localize`The upload failed` | ||
186 | let message = err.message | ||
187 | |||
188 | if (err instanceof ErrorEvent) { // network error | ||
189 | message = $localize`The connection was interrupted` | ||
190 | notifier.error(message, title, null, sticky) | ||
191 | } else if (err.status === HttpStatusCode.REQUEST_TIMEOUT_408) { | ||
192 | message = $localize`Your ${name} file couldn't be transferred before the set timeout (usually 10min)` | ||
193 | notifier.error(message, title, null, sticky) | ||
194 | } else if (err.status === HttpStatusCode.PAYLOAD_TOO_LARGE_413) { | ||
195 | const maxFileSize = err.headers?.get('X-File-Maximum-Size') || '8G' | ||
196 | message = $localize`Your ${name} file was too large (max. size: ${maxFileSize})` | ||
197 | notifier.error(message, title, null, sticky) | ||
198 | } else { | ||
199 | notifier.error(err.message, title) | ||
200 | } | ||
201 | |||
202 | return message | ||
203 | } | ||
204 | |||
175 | export { | 205 | export { |
176 | sortBy, | 206 | sortBy, |
177 | durationToString, | 207 | durationToString, |
@@ -187,5 +217,6 @@ export { | |||
187 | removeElementFromArray, | 217 | removeElementFromArray, |
188 | scrollToTop, | 218 | scrollToTop, |
189 | isInViewport, | 219 | isInViewport, |
190 | isXPercentInViewport | 220 | isXPercentInViewport, |
221 | uploadErrorHandler | ||
191 | } | 222 | } |