API: Do not swallow downloadMedia exceptions
This commit is contained in:
parent
748c4994ab
commit
e4c30ea969
@ -280,25 +280,27 @@ function handleUpdatesFromRequest<T extends GramJs.AnyRequest>(request: T, resul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function downloadMedia(
|
export async function downloadMedia(
|
||||||
args: { url: string; mediaFormat: ApiMediaFormat; start?: number; end?: number; isHtmlAllowed?: boolean },
|
args: { url: string; mediaFormat: ApiMediaFormat; start?: number; end?: number; isHtmlAllowed?: boolean },
|
||||||
onProgress?: ApiOnProgress,
|
onProgress?: ApiOnProgress,
|
||||||
) {
|
) {
|
||||||
return downloadMediaWithClient(args, client, isConnected, onProgress).catch(async (err) => {
|
try {
|
||||||
|
return (await downloadMediaWithClient(args, client, isConnected, onProgress));
|
||||||
|
} catch (err: any) {
|
||||||
if (err.message.startsWith('FILE_REFERENCE')) {
|
if (err.message.startsWith('FILE_REFERENCE')) {
|
||||||
const isFileReferenceRepaired = await repairFileReference({ url: args.url });
|
const isFileReferenceRepaired = await repairFileReference({ url: args.url });
|
||||||
if (!isFileReferenceRepaired) {
|
if (isFileReferenceRepaired) {
|
||||||
if (DEBUG) {
|
return downloadMediaWithClient(args, client, isConnected, onProgress);
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error('Failed to repair file reference', args.url);
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return downloadMediaWithClient(args, client, isConnected, onProgress);
|
if (DEBUG) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('Failed to repair file reference', args.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
});
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uploadFile(file: File, onProgress?: ApiOnProgress) {
|
export function uploadFile(file: File, onProgress?: ApiOnProgress) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user