aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-11-23 10:45:42 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-12-03 10:15:49 +0100
commitd4132d3f56b392a2e4e632db59e6644e4851228e (patch)
treebe903734aa9ce3d669c40656a0f81bd3e9c7978c /client/src/app/helpers
parent4a54a93941d1c095bf249331df799c51e39c3774 (diff)
downloadPeerTube-d4132d3f56b392a2e4e632db59e6644e4851228e.tar.gz
PeerTube-d4132d3f56b392a2e4e632db59e6644e4851228e.tar.zst
PeerTube-d4132d3f56b392a2e4e632db59e6644e4851228e.zip
more explicit error messages for file uploads
Diffstat (limited to 'client/src/app/helpers')
-rw-r--r--client/src/app/helpers/utils.ts33
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 @@
1import { DatePipe } from '@angular/common' 1import { DatePipe } from '@angular/common'
2import { HttpErrorResponse } from '@angular/common/http'
3import { Notifier } from '@app/core'
2import { SelectChannelItem } from '@app/shared/shared-forms' 4import { SelectChannelItem } from '@app/shared/shared-forms'
3import { environment } from '../../environments/environment' 5import { environment } from '../../environments/environment'
4import { AuthService } from '../core/auth' 6import { AuthService } from '../core/auth'
7import { 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
7function getParameterByName (name: string, url: string) { 10function getParameterByName (name: string, url: string) {
@@ -172,6 +175,33 @@ function isXPercentInViewport (el: HTMLElement, percentVisible: number) {
172 ) 175 )
173} 176}
174 177
178function 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
175export { 205export {
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}