- checkErrors(req, res, () => {
- if (req.query.format !== undefined && req.query.format !== 'json') {
- return res.status(501)
- .json({ error: 'Requested format is not implemented on server.' })
- .end()
- }
-
- const startIsOk = req.query.url.startsWith(urlShouldStartWith)
- const matches = videoWatchRegex.exec(req.query.url)
- if (startIsOk === false || matches === null) {
- return res.status(400)
- .json({ error: 'Invalid url.' })
- .end()
- }
-
- const videoId = matches[1]
- if (isVideoIdOrUUIDValid(videoId) === false) {
- return res.status(400)
- .json({ error: 'Invalid video id.' })
- .end()
- }
-
- checkVideoExists(videoId, res, next)
- })
+ if (areValidationErrors(req, res)) return
+
+ if (req.query.format !== undefined && req.query.format !== 'json') {
+ return res.status(501)
+ .json({ error: 'Requested format is not implemented on server.' })
+ .end()
+ }
+
+ const startIsOk = req.query.url.startsWith(urlShouldStartWith)
+ const matches = videoWatchRegex.exec(req.query.url)
+ if (startIsOk === false || matches === null) {
+ return res.status(400)
+ .json({ error: 'Invalid url.' })
+ .end()
+ }
+
+ const videoId = matches[1]
+ if (isIdOrUUIDValid(videoId) === false) {
+ return res.status(400)
+ .json({ error: 'Invalid video id.' })
+ .end()
+ }
+
+ if (!await isVideoExist(videoId, res)) return
+
+ return next()