diff options
author | Ronan <flyingrub@protonmail.com> | 2017-10-16 11:43:40 +0200 |
---|---|---|
committer | Bigard Florian <florian.bigard@gmail.com> | 2017-10-16 11:43:40 +0200 |
commit | 8376734ee3a58edc960cb41663de5cc52c760f5b (patch) | |
tree | bf9fcdd489a5f1800049ee7dd5478138de3b097a | |
parent | d8755eed1e452d2efbfc983af0e9d228d152bf6b (diff) | |
download | PeerTube-8376734ee3a58edc960cb41663de5cc52c760f5b.tar.gz PeerTube-8376734ee3a58edc960cb41663de5cc52c760f5b.tar.zst PeerTube-8376734ee3a58edc960cb41663de5cc52c760f5b.zip |
Handle express-validator error on the client side and fix #96 (#98)
* Handle express-validator error on the client side
* More meaningfull error for not supported format
-rw-r--r-- | client/src/app/shared/rest/rest-extractor.service.ts | 15 | ||||
-rw-r--r-- | server/middlewares/validators/videos.ts | 5 |
2 files changed, 17 insertions, 3 deletions
diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts index aafc9723e..b560e2fe4 100644 --- a/client/src/app/shared/rest/rest-extractor.service.ts +++ b/client/src/app/shared/rest/rest-extractor.service.ts | |||
@@ -45,8 +45,19 @@ export class RestExtractor { | |||
45 | errorMessage = err.error.message | 45 | errorMessage = err.error.message |
46 | console.error('An error occurred:', errorMessage) | 46 | console.error('An error occurred:', errorMessage) |
47 | } else if (err.status !== undefined) { | 47 | } else if (err.status !== undefined) { |
48 | const body = err.error | 48 | // A server-side error occurred. |
49 | errorMessage = body ? body.error : 'Unknown error.' | 49 | // TODO: remove when angular/angular#19477 (comment) is fixed |
50 | let body = JSON.parse(err.error) | ||
51 | if (body) { | ||
52 | if (body.errors) { | ||
53 | const errors = body.errors | ||
54 | const error = errors[Object.keys(errors)[0]] | ||
55 | errorMessage = error.msg // Take the message of the first error | ||
56 | } else if (body.error) { | ||
57 | errorMessage = body.error | ||
58 | } | ||
59 | } | ||
60 | errorMessage = errorMessage ? errorMessage : 'Unknown error.' | ||
50 | console.error(`Backend returned code ${err.status}, body was: ${errorMessage}`) | 61 | console.error(`Backend returned code ${err.status}, body was: ${errorMessage}`) |
51 | } else { | 62 | } else { |
52 | errorMessage = err | 63 | errorMessage = err |
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index deed07524..f63348e66 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -23,7 +23,10 @@ import { | |||
23 | } from '../../helpers' | 23 | } from '../../helpers' |
24 | 24 | ||
25 | const videosAddValidator = [ | 25 | const videosAddValidator = [ |
26 | body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage('Should have a valid file'), | 26 | body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage( |
27 | 'This file is not supported. Are you sure it is of the following type : ' | ||
28 | + CONSTRAINTS_FIELDS.VIDEOS.EXTNAME | ||
29 | ), | ||
27 | body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), | 30 | body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), |
28 | body('category').custom(isVideoCategoryValid).withMessage('Should have a valid category'), | 31 | body('category').custom(isVideoCategoryValid).withMessage('Should have a valid category'), |
29 | body('licence').custom(isVideoLicenceValid).withMessage('Should have a valid licence'), | 32 | body('licence').custom(isVideoLicenceValid).withMessage('Should have a valid licence'), |