MOBILE-4109 core: Log unhandled errors

main
Noel De Martin 2022-11-17 11:34:22 +01:00
parent cd8f81d332
commit 56c4877b2e
2 changed files with 13 additions and 2 deletions

View File

@ -449,7 +449,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncCompo
* @param site Site instance. * @param site Site instance.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async treatHTMLElements(div: HTMLElement, site?: CoreSite): Promise<void> { protected treatHTMLElements(div: HTMLElement, site?: CoreSite): void {
const images = Array.from(div.querySelectorAll('img')); const images = Array.from(div.querySelectorAll('img'));
const anchors = Array.from(div.querySelectorAll('a')); const anchors = Array.from(div.querySelectorAll('a'));
const audios = Array.from(div.querySelectorAll('audio')); const audios = Array.from(div.querySelectorAll('audio'));
@ -560,7 +560,8 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncCompo
promises.push(CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(promise, 5000))); promises.push(CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(promise, 5000)));
} }
await Promise.all(promises); // Run asynchronous operations in the background to avoid blocking rendering.
Promise.all(promises).catch(error => CoreUtils.logUnhandledError('Error treating format-text elements', error));
} }
/** /**

View File

@ -139,6 +139,16 @@ export class CoreUtilsProvider {
return result; return result;
} }
/**
* Log an unhandled error.
*
* @param message Message to contextualize the error.
* @param error Error to log.
*/
logUnhandledError(message: string, error: unknown): void {
this.logger.error(message, error);
}
/** /**
* Converts an array of objects to an indexed array, using a property of each entry as the key. * Converts an array of objects to an indexed array, using a property of each entry as the key.
* Every entry will contain an array of the found objects of the property identifier. * Every entry will contain an array of the found objects of the property identifier.