1
0
Fork 0

Handle error for the video upload

This commit is contained in:
Chocobozzz 2016-06-04 20:37:38 +02:00
parent fe3b20cdaf
commit 1cdb5c0f58
4 changed files with 21 additions and 2 deletions

View file

@ -1,5 +1,7 @@
<h3>Upload a video</h3> <h3>Upload a video</h3>
<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
<form (ngSubmit)="uploadFile()" #videoForm="ngForm"> <form (ngSubmit)="uploadFile()" #videoForm="ngForm">
<div class="form-group"> <div class="form-group">
<label for="name">Video name</label> <label for="name">Video name</label>

View file

@ -18,6 +18,7 @@ import { AuthService, User } from '../../shared';
}) })
export class VideoAddComponent implements OnInit { export class VideoAddComponent implements OnInit {
error: string = null;
fileToUpload: any; fileToUpload: any;
progressBar: { value: number; max: number; } = { value: 0, max: 0 }; progressBar: { value: number; max: number; } = { value: 0, max: 0 };
user: User; user: User;
@ -57,11 +58,23 @@ export class VideoAddComponent implements OnInit {
// Print all the videos once it's finished // Print all the videos once it's finished
this.router.navigate(['VideosList']); 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() { uploadFile() {
this.error = null;
this.form.formData = jQuery(this.elementRef.nativeElement).find('form').serializeArray(); this.form.formData = jQuery(this.elementRef.nativeElement).find('form').serializeArray();
this.form.headers = this.authService.getRequestHeader().toJSON(); this.form.headers = this.authService.getRequestHeader().toJSON();
this.form.submit(); this.form.submit();

View file

@ -1,5 +1,9 @@
<div class="row videos-info"> <div class="row videos-info">
<div class="col-md-9 videos-total-results"> {{ pagination.total }} videos</div> <div class="col-md-9 videos-total-results">
{{ pagination.total }} videos
<my-loader [loading]="loading"></my-loader>
</div>
<my-video-sort class="col-md-3" [currentSort]="sort" (sort)="onSort($event)"></my-video-sort> <my-video-sort class="col-md-3" [currentSort]="sort" (sort)="onSort($event)"></my-video-sort>
</div> </div>

View file

@ -30,7 +30,7 @@ function videosAdd (req, res, next) {
} }
if (duration > constants.MAXIMUM_VIDEO_DURATION) { 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 videoFile.duration = duration