From 151ef5734038b6382f488f37b304ad57657a568e Mon Sep 17 00:00:00 2001 From: Saelmala Date: Mon, 4 Nov 2024 10:34:35 +0100 Subject: [PATCH 1/2] fix: error handling stop production --- .../renderingengine/renderingengine.ts | 26 +++++++++++++++++-- src/api/manager/workflow.ts | 16 +++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts b/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts index 68507b9d..fb601612 100644 --- a/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts +++ b/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts @@ -529,11 +529,33 @@ export async function getPipelineRenderingEngine( method: 'GET', headers: { authorization: getAuthorizationHeader() + }, + next: { + revalidate: 0 } } ); + if (response.ok) { - return await response.json(); + try { + return await response.json(); + } catch (error) { + console.error('Failed to parse successful JSON response:', error); + throw new Error('Parsing error in successful response.'); + } + } + + const contentType = response.headers.get('content-type'); + const responseText = await response.text(); + + if (contentType && contentType.includes('application/json')) { + try { + throw JSON.parse(responseText); + } catch (error) { + console.error('Failed to parse JSON error response:', error); + throw new Error(`Failed to parse JSON error response: ${responseText}`); + } + } else { + throw new Error(`Unexpected non-JSON response: ${responseText}`); } - throw await response.json(); } diff --git a/src/api/manager/workflow.ts b/src/api/manager/workflow.ts index 6520377b..a9d7ca26 100644 --- a/src/api/manager/workflow.ts +++ b/src/api/manager/workflow.ts @@ -378,10 +378,12 @@ export async function stopProduction( } for (const source of production.sources) { - for (const stream_uuid of source.stream_uuids || []) { - await deleteStreamByUuid(stream_uuid).catch((error) => { - Log().error('Failed to delete stream! \nError: ', error); - }); + if (source.type === 'ingest_source') { + for (const stream_uuid of source.stream_uuids || []) { + await deleteStreamByUuid(stream_uuid).catch((error) => { + Log().error('Failed to delete stream! \nError: ', error); + }); + } } } @@ -441,7 +443,7 @@ export async function stopProduction( value: { step: 'remove_pipeline_streams', success: false, - message: 'Unexpected error occured' + message: `Error occurred when removing streams from pipeline: ${e}` } }; } else { @@ -464,7 +466,7 @@ export async function stopProduction( value: { step: 'remove_pipeline_multiviews', success: false, - message: 'Unexpected error occured' + message: `Error occurred when removing multiviews from pipeline: ${e}` } }; } else { @@ -638,7 +640,7 @@ export async function startProduction( return { ok: false, value: [{ step: 'streams', success: false }], - error: 'Could not setup streams: Unexpected error occured' + error: `Could not setup streams: Unexpected error occured: ${e}` }; } return { From 0644df397d8f7f4eb6692d51c58a1040ab0845ef Mon Sep 17 00:00:00 2001 From: Saelmala Date: Mon, 4 Nov 2024 10:39:54 +0100 Subject: [PATCH 2/2] fix: test fails --- .../ateliereLive/pipelines/renderingengine/renderingengine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts b/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts index fb601612..15cb7428 100644 --- a/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts +++ b/src/api/ateliereLive/pipelines/renderingengine/renderingengine.ts @@ -529,7 +529,7 @@ export async function getPipelineRenderingEngine( method: 'GET', headers: { authorization: getAuthorizationHeader() - }, + }, next: { revalidate: 0 }