refactor: improve task error message
[poolifier.git] / src / worker / abstract-worker.ts
index 0646a9bfa0e423bd466ccc16efeba8b4782067c7..63d14b2ed2dbd2a592451a7d8363564f8d6c9fbe 100644 (file)
@@ -206,7 +206,7 @@ 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.
-   * @returns Message of the error.
+   * @returns The error message.
    */
   protected handleError (e: Error | string): string {
     return e as string
@@ -236,10 +236,10 @@ export abstract class AbstractWorker<
       const err = this.handleError(e as Error)
       this.sendToMainWorker({
         taskError: {
+          workerId: this.id,
           message: err,
           data: message.data
         },
-        workerId: this.id,
         id: message.id
       })
     } finally {
@@ -273,10 +273,10 @@ export abstract class AbstractWorker<
         const err = this.handleError(e as Error)
         this.sendToMainWorker({
           taskError: {
+            workerId: this.id,
             message: err,
             data: message.data
           },
-          workerId: this.id,
           id: message.id
         })
       })