Modified the try-catch block

This commit is contained in:
Vijay
2024-03-07 21:32:46 +05:30
parent da7c83774c
commit 284226166e

View File

@@ -88,22 +88,16 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
if (!output || (!output.stream?.length && !output.embeds.length)) { if (!output || (!output.stream?.length && !output.embeds.length)) {
throw new NotFoundError('No streams found'); throw new NotFoundError('No streams found');
} }
} catch (err) { } catch (error) {
if (err instanceof NotFoundError) { const updateParams: UpdateEvent = {
ops.events?.update?.({
id: source.id,
percentage: 100,
status: 'notfound',
reason: err.message,
});
continue;
}
ops.events?.update?.({
id: source.id, id: source.id,
percentage: 100, percentage: 100,
status: 'failure', status: error instanceof NotFoundError ? 'notfound' : 'failure',
error: err, reason: error instanceof NotFoundError ? error.message : undefined,
}); error: error instanceof NotFoundError ? undefined : error,
};
ops.events?.update?.(updateParams);
continue; continue;
} }
if (!output) throw new Error('Invalid media type'); if (!output) throw new Error('Invalid media type');
@@ -161,16 +155,11 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
percentage: 100, percentage: 100,
status: error instanceof NotFoundError ? 'notfound' : 'failure', status: error instanceof NotFoundError ? 'notfound' : 'failure',
reason: error instanceof NotFoundError ? error.message : undefined, reason: error instanceof NotFoundError ? error.message : undefined,
error, error: error instanceof NotFoundError ? undefined : error,
}; };
ops.events?.update?.(updateParams); ops.events?.update?.(updateParams);
continue;
if (error instanceof NotFoundError) {
continue;
}
throw error;
} }
return { return {