From 1cdb5c0f582502eac4d851cecc015e81cf16316b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 4 Jun 2016 20:37:38 +0200 Subject: [PATCH] Handle error for the video upload --- .../app/videos/video-add/video-add.component.html | 2 ++ .../src/app/videos/video-add/video-add.component.ts | 13 +++++++++++++ .../app/videos/video-list/video-list.component.html | 6 +++++- server/middlewares/reqValidators/videos.js | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/client/src/app/videos/video-add/video-add.component.html b/client/src/app/videos/video-add/video-add.component.html index 80d229cb8..cbe274e8a 100644 --- a/client/src/app/videos/video-add/video-add.component.html +++ b/client/src/app/videos/video-add/video-add.component.html @@ -1,5 +1,7 @@

Upload a video

+
{{ error }}
+
diff --git a/client/src/app/videos/video-add/video-add.component.ts b/client/src/app/videos/video-add/video-add.component.ts index 8df4f951b..144879a54 100644 --- a/client/src/app/videos/video-add/video-add.component.ts +++ b/client/src/app/videos/video-add/video-add.component.ts @@ -18,6 +18,7 @@ import { AuthService, User } from '../../shared'; }) export class VideoAddComponent implements OnInit { + error: string = null; fileToUpload: any; progressBar: { value: number; max: number; } = { value: 0, max: 0 }; user: User; @@ -57,11 +58,23 @@ export class VideoAddComponent implements OnInit { // Print all the videos once it's finished this.router.navigate(['VideosList']); + }, + + fail: (e, data) => { + const xhr = data.jqXHR; + if (xhr.status === 400) { + this.error = xhr.responseText; + } else { + this.error = 'Unknow error'; + } + + console.error(data); } }); } uploadFile() { + this.error = null; this.form.formData = jQuery(this.elementRef.nativeElement).find('form').serializeArray(); this.form.headers = this.authService.getRequestHeader().toJSON(); this.form.submit(); diff --git a/client/src/app/videos/video-list/video-list.component.html b/client/src/app/videos/video-list/video-list.component.html index 155025b5e..00392a81f 100644 --- a/client/src/app/videos/video-list/video-list.component.html +++ b/client/src/app/videos/video-list/video-list.component.html @@ -1,5 +1,9 @@
-
{{ pagination.total }} videos
+
+ {{ pagination.total }} videos + + +
diff --git a/server/middlewares/reqValidators/videos.js b/server/middlewares/reqValidators/videos.js index d444c9f0a..10b6d39c6 100644 --- a/server/middlewares/reqValidators/videos.js +++ b/server/middlewares/reqValidators/videos.js @@ -30,7 +30,7 @@ function videosAdd (req, res, next) { } if (duration > constants.MAXIMUM_VIDEO_DURATION) { - return res.status(400).send('Duration of the video file is too big (' + constants.MAXIMUM_VIDEO_DURATION + ').') + return res.status(400).send('Duration of the video file is too big (max: ' + constants.MAXIMUM_VIDEO_DURATION + 's).') } videoFile.duration = duration -- 2.41.0