refactor: no throw literal in utilsController

This commit is contained in:
Bobby Wibowo 2021-01-08 09:56:01 +07:00
parent b5af733dc2
commit 1142b64e3c
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -218,7 +218,7 @@ self.generateThumbs = async (name, extname, force) => {
return true return true
} }
} catch (error) { } catch (error) {
// Re-throw error // Re-throw non-ENOENT error
if (error.code !== 'ENOENT') throw error if (error.code !== 'ENOENT') throw error
} }
@ -265,12 +265,12 @@ self.generateThumbs = async (name, extname, force) => {
const duration = parseInt(metadata.format.duration) const duration = parseInt(metadata.format.duration)
if (isNaN(duration)) { if (isNaN(duration)) {
throw 'Warning: File does not have valid duration metadata' throw new Error('File does not have valid duration metadata')
} }
const videoStream = metadata.streams && metadata.streams.find(s => s.codec_type === 'video') const videoStream = metadata.streams && metadata.streams.find(s => s.codec_type === 'video')
if (!videoStream || !videoStream.width || !videoStream.height) { if (!videoStream || !videoStream.width || !videoStream.height) {
throw 'Warning: File does not have valid video stream metadata' throw new Error('File does not have valid video stream metadata')
} }
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
@ -297,7 +297,7 @@ self.generateThumbs = async (name, extname, force) => {
return true return true
} catch (err) { } catch (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
throw error || 'Warning: FFMPEG exited with empty output file' throw error || new Error('FFMPEG exited with empty output file')
} else { } else {
throw error || err throw error || err
} }