From 76148b27f7501bac061992136852be4303370c8d Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 1 Jun 2021 01:36:53 +0200 Subject: refactor API errors to standard error format --- server/controllers/api/videos/import.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'server/controllers/api/videos/import.ts') 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 { } from '@server/types/models' import { MVideoImportFormattable } from '@server/types/models/video/video-import' import { ServerErrorCode, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' @@ -143,10 +142,12 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) } catch (err) { logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err }) - return res.status(HttpStatusCode.BAD_REQUEST_400) - .json({ - error: 'Cannot fetch remote information of this URL.' - }) + return res.fail({ + message: 'Cannot fetch remote information of this URL.', + data: { + targetUrl + } + }) } const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) @@ -333,12 +334,10 @@ async function processTorrentOrAbortRequest (req: express.Request, res: express. if (parsedTorrent.files.length !== 1) { cleanUpReqFiles(req) - res.status(HttpStatusCode.BAD_REQUEST_400) - .json({ - code: ServerErrorCode.INCORRECT_FILES_IN_TORRENT, - error: 'Torrents with only 1 file are supported.' - }) - + res.fail({ + type: ServerErrorCode.INCORRECT_FILES_IN_TORRENT.toString(), + message: 'Torrents with only 1 file are supported.' + }) return undefined } -- cgit v1.2.3