mirror of https://github.com/Chocobozzz/PeerTube
* Handle express-validator error on the client side * More meaningfull error for not supported formatpull/108/head
parent
d8755eed1e
commit
8376734ee3
|
@ -45,8 +45,19 @@ export class RestExtractor {
|
||||||
errorMessage = err.error.message
|
errorMessage = err.error.message
|
||||||
console.error('An error occurred:', errorMessage)
|
console.error('An error occurred:', errorMessage)
|
||||||
} else if (err.status !== undefined) {
|
} else if (err.status !== undefined) {
|
||||||
const body = err.error
|
// A server-side error occurred.
|
||||||
errorMessage = body ? body.error : 'Unknown error.'
|
// TODO: remove when angular/angular#19477 (comment) is fixed
|
||||||
|
let body = JSON.parse(err.error)
|
||||||
|
if (body) {
|
||||||
|
if (body.errors) {
|
||||||
|
const errors = body.errors
|
||||||
|
const error = errors[Object.keys(errors)[0]]
|
||||||
|
errorMessage = error.msg // Take the message of the first error
|
||||||
|
} else if (body.error) {
|
||||||
|
errorMessage = body.error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errorMessage = errorMessage ? errorMessage : 'Unknown error.'
|
||||||
console.error(`Backend returned code ${err.status}, body was: ${errorMessage}`)
|
console.error(`Backend returned code ${err.status}, body was: ${errorMessage}`)
|
||||||
} else {
|
} else {
|
||||||
errorMessage = err
|
errorMessage = err
|
||||||
|
|
|
@ -23,7 +23,10 @@ import {
|
||||||
} from '../../helpers'
|
} from '../../helpers'
|
||||||
|
|
||||||
const videosAddValidator = [
|
const videosAddValidator = [
|
||||||
body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage('Should have a valid file'),
|
body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage(
|
||||||
|
'This file is not supported. Are you sure it is of the following type : '
|
||||||
|
+ CONSTRAINTS_FIELDS.VIDEOS.EXTNAME
|
||||||
|
),
|
||||||
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
|
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
|
||||||
body('category').custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
body('category').custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
||||||
body('licence').custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
body('licence').custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
||||||
|
|
Loading…
Reference in New Issue