1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Reduce error output on muxing error

This commit is contained in:
Chocobozzz 2025-02-24 14:48:08 +01:00
parent b608a075c9
commit 0e8fff084a
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 33 additions and 28 deletions

View file

@ -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 <T> (url: string, options: PeerTubeRequestOptions & { preventSSRF?: false } = {}) {
export function doJSONRequest<T> (url: string, options: PeerTubeRequestOptions & { preventSSRF?: false } = {}) {
const gotOptions = buildGotOptions(options)
const gotInstance = options.preventSSRF === false
@ -149,7 +150,9 @@ export function doJSONRequest <T> (url: string, options: PeerTubeRequestOptions
: peertubeGot
return gotInstance<T>(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<any>) {
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)

View file

@ -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
// ---------------------------------------------------------------------------