Skip to content

Commit

Permalink
Fetch error should return status 400 (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed Aug 4, 2022
1 parent db19d06 commit cbdbb67
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/controllers/api/videos/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ async function handleTorrentImport (req: express.Request, res: express.Response,
return res.json(videoImport.toFormattedJSON()).end()
}

function statusFromYtDlImportError (err: YoutubeDlImportError): number {
switch (err.code) {
case YoutubeDlImportError.CODE.NOT_ONLY_UNICAST_URL:
return HttpStatusCode.FORBIDDEN_403
case YoutubeDlImportError.CODE.FETCH_ERROR:
return HttpStatusCode.BAD_REQUEST_400
default:
return HttpStatusCode.INTERNAL_SERVER_ERROR_500
}
}

async function handleYoutubeDlImport (req: express.Request, res: express.Response) {
const body: VideoImportCreate = req.body
const targetUrl = body.targetUrl
Expand All @@ -170,9 +181,7 @@ async function handleYoutubeDlImport (req: express.Request, res: express.Respons
logger.error('An error occurred while importing the video %s. ', targetUrl, { err })
return res.fail({
message: err.message,
status: err.code === YoutubeDlImportError.CODE.NOT_ONLY_UNICAST_URL
? HttpStatusCode.FORBIDDEN_403
: HttpStatusCode.INTERNAL_SERVER_ERROR_500,
status: statusFromYtDlImportError(err),
data: {
targetUrl
}
Expand Down

0 comments on commit cbdbb67

Please sign in to comment.