diff --git a/server/core/helpers/requests.ts b/server/core/helpers/requests.ts index dee90b9f8..6ea86df56 100644 --- a/server/core/helpers/requests.ts +++ b/server/core/helpers/requests.ts @@ -70,8 +70,7 @@ export const unsafeSSRFGot = got.extend({ return } - // Stream - (promiseOrStream as any).destroy() + ;(promiseOrStream as any).destroy() } }) @@ -138,10 +137,12 @@ export function doRequest (url: string, options: PeerTubeRequestOptions & { prev : peertubeGot return gotInstance(url, gotOptions) - .catch(err => { throw buildRequestError(err) }) + .catch(err => { + throw buildRequestError(err) + }) } -export function doJSONRequest (url: string, options: PeerTubeRequestOptions & { preventSSRF?: false } = {}) { +export function doJSONRequest (url: string, options: PeerTubeRequestOptions & { preventSSRF?: false } = {}) { const gotOptions = buildGotOptions(options) const gotInstance = options.preventSSRF === false @@ -149,7 +150,9 @@ export function doJSONRequest (url: string, options: PeerTubeRequestOptions : peertubeGot return gotInstance(url, { ...gotOptions, responseType: 'json' }) - .catch(err => { throw buildRequestError(err) }) + .catch(err => { + throw buildRequestError(err) + }) } export async function doRequestAndSaveToFile (url: string, destPath: string, options: PeerTubeRequestOptions = {}) { @@ -211,6 +214,26 @@ export function isBinaryResponse (result: Response) { return BINARY_CONTENT_TYPES.has(result.headers['content-type']) } +export function buildRequestError (error: RequestError) { + const newError: PeerTubeRequestError = new Error(error.message) + newError.name = error.name + newError.stack = error.stack + + if (error.response) { + newError.responseBody = error.response.body + newError.responseHeaders = error.response.headers + newError.statusCode = error.response.statusCode + } + + if (error.options) { + newError.requestHeaders = error.options.headers + newError.requestUrl = error.options.url + newError.requestMethod = error.options.method + } + + return newError +} + // --------------------------------------------------------------------------- // Private // --------------------------------------------------------------------------- @@ -251,26 +274,6 @@ function buildGotOptions (options: PeerTubeRequestOptions): OptionsOfUnknownResp } } -function buildRequestError (error: RequestError) { - const newError: PeerTubeRequestError = new Error(error.message) - newError.name = error.name - newError.stack = error.stack - - if (error.response) { - newError.responseBody = error.response.body - newError.responseHeaders = error.response.headers - newError.statusCode = error.response.statusCode - } - - if (error.options) { - newError.requestHeaders = error.options.headers - newError.requestUrl = error.options.url - newError.requestMethod = error.options.method - } - - return newError -} - function buildUrl (url: string | URL) { if (typeof url === 'string') { return new URL(url) diff --git a/server/core/lib/video-file.ts b/server/core/lib/video-file.ts index 365b69a0e..5a0e2f801 100644 --- a/server/core/lib/video-file.ts +++ b/server/core/lib/video-file.ts @@ -11,7 +11,7 @@ import { FileStorage, VideoFileFormatFlag, VideoFileMetadata, VideoFileStream, V import { getFileSize, getLowercaseExtension } from '@peertube/peertube-node-utils' import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/ffmpeg-options.js' import { logger, loggerTagsFactory } from '@server/helpers/logger.js' -import { doRequestAndSaveToFile, generateRequestStream } from '@server/helpers/requests.js' +import { buildRequestError, doRequestAndSaveToFile, generateRequestStream } from '@server/helpers/requests.js' import { CONFIG } from '@server/initializers/config.js' import { MIMETYPES, REQUEST_TIMEOUTS } from '@server/initializers/constants.js' import { VideoFileModel } from '@server/models/video/video-file.js' @@ -324,9 +324,12 @@ export async function muxToMergeVideoFiles (options: { logger.warn(`Cannot mux files of video ${video.url}`, { err, inputs: inputsToLog, ...lTags(video.uuid) }) + if (err.inputStreamError) { + err.inputStreamError = buildRequestError(err.inputStreamError) + } + throw err } - } finally { for (const destination of tmpDestinations) { await remove(destination) @@ -338,7 +341,6 @@ async function buildMuxInput ( video: MVideo, videoFile: MVideoFile ): Promise<{ input: Readable, isTmpDestination: false } | { input: string, isTmpDestination: boolean }> { - // --------------------------------------------------------------------------- // Remote // ---------------------------------------------------------------------------