diff --git a/Source/JavaScript/Applications/commands/Command.ts b/Source/JavaScript/Applications/commands/Command.ts index fa89ff0d..c35d1f80 100644 --- a/Source/JavaScript/Applications/commands/Command.ts +++ b/Source/JavaScript/Applications/commands/Command.ts @@ -26,7 +26,7 @@ export abstract class Command imple private _initialValues: any = {}; private _hasChanges = false; private _callbacks: Callback[] = []; - + /** * Initializes a new instance of the {@link Command<,>} class. * @param _responseType Type of response. @@ -62,18 +62,22 @@ export abstract class Command imple headers[Globals.microserviceHttpHeader] = Globals.microservice; } - const response = await fetch(actualRoute, { - method: 'POST', - headers, - body: JSON.stringify(payload) - }); - this.setInitialValuesFromCurrentValues(); - try { + const response = await fetch(actualRoute, { + method: 'POST', + headers, + body: JSON.stringify(payload) + }); + this.setInitialValuesFromCurrentValues(); + + if( response.status === 404) { + return CommandResult.failed([`Command not found at route '${actualRoute}'`]) as CommandResult; + } + const result = await response.json(); return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable); } catch (ex) { - return CommandResult.empty as CommandResult; + return CommandResult.failed([`Error during server call: ${ex}`]) as CommandResult; } } diff --git a/Source/JavaScript/Applications/commands/CommandResult.ts b/Source/JavaScript/Applications/commands/CommandResult.ts index 259e7379..2370408b 100644 --- a/Source/JavaScript/Applications/commands/CommandResult.ts +++ b/Source/JavaScript/Applications/commands/CommandResult.ts @@ -45,6 +45,20 @@ export class CommandResult implements ICommandResult response: null }, Object, false); + static failed = (exceptionMessages: string[]): CommandResult => { + return new CommandResult({ + correlationId: Guid.empty.toString(), + isSuccess: false, + isAuthorized: true, + isValid: true, + hasExceptions: true, + validationResults: [], + exceptionMessages: exceptionMessages, + exceptionStackTrace: '', + response: null + }, Object, false); + }; + /** @inheritdoc */ readonly correlationId: Guid;