From 646bced2dd1695fbb7c8595f37b4713f44b03fb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 16 Sep 2023 23:58:38 +0200 Subject: [PATCH] refactor: code cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/abstract-worker.ts | 16 +++++++--------- src/worker/thread-worker.ts | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 5b3c3a3f..cd8f2346 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -460,11 +460,11 @@ export abstract class AbstractWorker< /** * Handles an error and convert it to a string so it can be sent back to the main worker. * - * @param e - The error raised by the worker. + * @param error - The error raised by the worker. * @returns The error message. */ - protected handleError (e: Error | string): string { - return e instanceof Error ? e.message : e + protected handleError (error: Error | string): string { + return error instanceof Error ? error.message : error } /** @@ -516,12 +516,11 @@ export abstract class AbstractWorker< workerId: this.id, taskId }) - } catch (e) { - const errorMessage = this.handleError(e as Error | string) + } catch (error) { this.sendToMainWorker({ taskError: { name: name as string, - message: errorMessage, + message: this.handleError(error as Error | string), data }, workerId: this.id, @@ -555,12 +554,11 @@ export abstract class AbstractWorker< }) return null }) - .catch(e => { - const errorMessage = this.handleError(e as Error | string) + .catch(error => { this.sendToMainWorker({ taskError: { name: name as string, - message: errorMessage, + message: this.handleError(error as Error | string), data }, workerId: this.id, diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 8d30ef21..d6a36992 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -93,7 +93,7 @@ export class ThreadWorker< } /** @inheritDoc */ - protected handleError (e: Error | string): string { - return e as string + protected handleError (error: Error | string): string { + return error as string } } -- 2.34.1