aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/import.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2021-06-01 01:36:53 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-06-02 16:57:07 +0200
commit76148b27f7501bac061992136852be4303370c8d (patch)
treefc0559253e833c9252fa14ebaec5321d88bfb4e8 /server/controllers/api/videos/import.ts
parent5ed25fb76e920dac364cb9ef46f14ec4bd372949 (diff)
downloadPeerTube-76148b27f7501bac061992136852be4303370c8d.tar.gz
PeerTube-76148b27f7501bac061992136852be4303370c8d.tar.zst
PeerTube-76148b27f7501bac061992136852be4303370c8d.zip
refactor API errors to standard error format
Diffstat (limited to 'server/controllers/api/videos/import.ts')
-rw-r--r--server/controllers/api/videos/import.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 0d5d7a962..6ee109a8f 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -18,7 +18,6 @@ import {
18} from '@server/types/models' 18} from '@server/types/models'
19import { MVideoImportFormattable } from '@server/types/models/video/video-import' 19import { MVideoImportFormattable } from '@server/types/models/video/video-import'
20import { ServerErrorCode, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' 20import { ServerErrorCode, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared'
21import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 21import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
23import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' 22import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
24import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' 23import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
@@ -143,10 +142,12 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
143 } catch (err) { 142 } catch (err) {
144 logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err }) 143 logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err })
145 144
146 return res.status(HttpStatusCode.BAD_REQUEST_400) 145 return res.fail({
147 .json({ 146 message: 'Cannot fetch remote information of this URL.',
148 error: 'Cannot fetch remote information of this URL.' 147 data: {
149 }) 148 targetUrl
149 }
150 })
150 } 151 }
151 152
152 const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) 153 const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo)
@@ -333,12 +334,10 @@ async function processTorrentOrAbortRequest (req: express.Request, res: express.
333 if (parsedTorrent.files.length !== 1) { 334 if (parsedTorrent.files.length !== 1) {
334 cleanUpReqFiles(req) 335 cleanUpReqFiles(req)
335 336
336 res.status(HttpStatusCode.BAD_REQUEST_400) 337 res.fail({
337 .json({ 338 type: ServerErrorCode.INCORRECT_FILES_IN_TORRENT.toString(),
338 code: ServerErrorCode.INCORRECT_FILES_IN_TORRENT, 339 message: 'Torrents with only 1 file are supported.'
339 error: 'Torrents with only 1 file are supported.' 340 })
340 })
341
342 return undefined 341 return undefined
343 } 342 }
344 343