From 365bc9b7ac9d3e4d8b22dde8cdfa8307ccfa3319 Mon Sep 17 00:00:00 2001
From: clauspeterhuebner
Date: Thu, 19 Feb 2026 01:32:54 +0100
Subject: [PATCH] correct result processing of execute method
---
core/src/command/BaseCommand.ts | 2 +-
core/src/command/Command.ts | 2 +-
core/src/command/CommandExecutor.ts | 37 +-----------------
core/src/command/commands/SendEmailCommand.ts | 38 +++++++++++++++++--
4 files changed, 39 insertions(+), 40 deletions(-)
diff --git a/core/src/command/BaseCommand.ts b/core/src/command/BaseCommand.ts
index 6c60ce7bd..6f32fa41d 100644
--- a/core/src/command/BaseCommand.ts
+++ b/core/src/command/BaseCommand.ts
@@ -12,7 +12,7 @@ export abstract class BaseCommand implements Command {
// this.validateRequiredFields();
}
- abstract execute(): Promise | boolean | null | Error>;
+ abstract execute(): Promise;
private validateRequiredFields(): void {
const methodLogger = createLogger(`validateRequiredFields`)
diff --git a/core/src/command/Command.ts b/core/src/command/Command.ts
index ac1392dc5..abd498474 100644
--- a/core/src/command/Command.ts
+++ b/core/src/command/Command.ts
@@ -1,4 +1,4 @@
export interface Command {
- execute(): Promise | boolean | null | Error>;
+ execute(): Promise;
validate?(): boolean;
}
diff --git a/core/src/command/CommandExecutor.ts b/core/src/command/CommandExecutor.ts
index f4987c2a1..3a7193bac 100644
--- a/core/src/command/CommandExecutor.ts
+++ b/core/src/command/CommandExecutor.ts
@@ -23,9 +23,8 @@ export class CommandExecutor {
}
methodLogger.debug(`executeCommand() executing command=${command.constructor.name}`)
const result = await command.execute();
- const resultMsg = this.getEmailResult(result);
- methodLogger.debug(`executeCommand() executed email-result=${resultMsg}`)
- return { success: true, data: resultMsg };
+ methodLogger.debug(`executeCommand() executed result=${result}`)
+ return { success: true, data: result };
} catch (error) {
methodLogger.error(`executeCommand() error=${error}`)
return {
@@ -71,36 +70,4 @@ export class CommandExecutor {
return errorResult;
}
}
-
- private getEmailResult(result: Record | boolean | null | Error): string {
- const methodLogger = createLogger(`getEmailResult`)
- if (methodLogger.isDebugEnabled()) {
- methodLogger.debug(`getEmailResult() result=${JSON.stringify(result)}`)
- }
- let emailResult: string;
- if(result === null) {
- emailResult = `getEmailResult() result is null`
- }
- else if(typeof result === 'boolean') {
- emailResult = `getEmailResult() result is ${result}`
- }
- else if(result instanceof Error) {
- emailResult = `getEmailResult() error-message is ${result.message}`
- }
- else if(typeof result === 'object') {
- // "accepted":["stage5@gradido.net"],"rejected":[],"ehlo":["PIPELINING","SIZE 25600000","ETRN","AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN","ENHANCEDSTATUSCODES","8BITMIME","DSN","CHUNKING"],"envelopeTime":25,"messageTime":146,"messageSize":37478,"response":"250 2.0.0 Ok: queued as 14B46100B7F","envelope":{"from":"stage5@gradido.net","to":["stage5@gradido.net"]}
-
- const accepted = (result as Record).accepted;
- const messageSize = (result as Record).messageSize;
- const response = (result as Record).response;
- const envelope = (result as Record).envelope;
- emailResult = `getEmailResult() accepted=${accepted}, messageSize=${messageSize}, response=${response}, envelope=${envelope}`
- }
- else {
- emailResult = `getEmailResult() result is unknown type`
- }
-
- return emailResult;
- }
-
}
diff --git a/core/src/command/commands/SendEmailCommand.ts b/core/src/command/commands/SendEmailCommand.ts
index 2a67bdd94..c43ce009c 100644
--- a/core/src/command/commands/SendEmailCommand.ts
+++ b/core/src/command/commands/SendEmailCommand.ts
@@ -39,10 +39,10 @@ export class SendEmailCommand extends BaseCommand | bool
return true;
}
- async execute(): Promise | boolean | null | Error> {
+ async execute(): Promise {
const methodLogger = createLogger(`execute`)
methodLogger.debug(`execute() sendEmailCommandParams=${JSON.stringify(this.sendEmailCommandParams)}`)
- let result: Record | boolean | null | Error;
+ let result: string;
if (!this.validate()) {
throw new Error('Invalid command parameters');
}
@@ -79,7 +79,8 @@ export class SendEmailCommand extends BaseCommand | bool
methodLogger.debug(`emailParams=${JSON.stringify(emailParams)}`)
switch(this.sendEmailCommandParams.mailType) {
case 'sendTransactionReceivedEmail':
- result = await sendTransactionReceivedEmail(emailParams);
+ const emailResult = await sendTransactionReceivedEmail(emailParams);
+ result = this.getEmailResult(emailResult);
break;
default:
throw new Error(`Unknown mail type: ${this.sendEmailCommandParams.mailType}`);
@@ -93,4 +94,35 @@ export class SendEmailCommand extends BaseCommand | bool
throw error;
}
}
+
+ private getEmailResult(result: Record | boolean | null | Error): string {
+ const methodLogger = createLogger(`getEmailResult`)
+ if (methodLogger.isDebugEnabled()) {
+ methodLogger.debug(`getEmailResult() result=${JSON.stringify(result)}`)
+ }
+ let emailResult: string;
+ if(result === null) {
+ emailResult = `getEmailResult() result is null`
+ }
+ else if(typeof result === 'boolean') {
+ emailResult = `getEmailResult() result is ${result}`
+ }
+ else if(result instanceof Error) {
+ emailResult = `getEmailResult() error-message is ${result.message}`
+ }
+ else if(typeof result === 'object') {
+ // {"accepted":["stage5@gradido.net"],"rejected":[],"ehlo":["PIPELINING","SIZE 25600000","ETRN","AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN","ENHANCEDSTATUSCODES","8BITMIME","DSN","CHUNKING"],"envelopeTime":23,"messageTime":135,"messageSize":37478,"response":"250 2.0.0 Ok: queued as C45C2100BD7","envelope":{"from":"stage5@gradido.net","to":["stage5@gradido.net"]},"messageId":""
+ const accepted = (result as Record).accepted;
+ const messageSize = (result as Record).messageSize;
+ const response = (result as Record).response;
+ const envelope = JSON.stringify((result as Record).envelope);
+ emailResult = `getEmailResult() accepted=${accepted}, messageSize=${messageSize}, response=${response}, envelope=${envelope}`
+ }
+ else {
+ emailResult = `getEmailResult() result is unknown type`
+ }
+
+ return emailResult;
+ }
+
}
\ No newline at end of file