From 8ef0aee76897581a4676a9eac6153a5eddcd8ad6 Mon Sep 17 00:00:00 2001 From: Alexander Puschkin Date: Tue, 5 Aug 2025 09:20:17 +0200 Subject: [PATCH] AAE-36869 Handles error messages with wrong JSON format (#11078) * Handles error messages with wrong JSON format Handles cases where the error message from the backend is not a valid JSON. If the message is not a valid JSON, it displays the error as a string. This prevents the application from crashing when receiving error messages with wrong JSON format. Fixes AAE-36869 * SonarCloud solution * Displays the error message from the response The error message is now extracted from the response body, providing more context when process start fails. This change ensures that the user sees the specific error message returned by the service when a process instance cannot be started, improving the user experience. * Refactors start process template to use `@if` blocks Migrates the start process component template from `*ngIf` directives to the new Angular `@if` syntax for improved readability and performance. This change enhances the structure and efficiency of conditional rendering within the template. * prettier --- .../start-process-cloud.component.html | 273 +++++++++--------- .../start-process-cloud.component.scss | 4 + .../start-process-cloud.component.spec.ts | 19 +- .../start-process-cloud.component.ts | 12 +- 4 files changed, 162 insertions(+), 146 deletions(-) diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.html b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.html index b75d7f45a8..3d789e623f 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.html +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.html @@ -1,147 +1,154 @@ - +@if (processDefinitionLoaded) { + + + @if (showTitle) { + + {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.TITLE' | translate }} + + } - - - {{'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.TITLE' | translate}} - + @if (errorMessageId) { + + {{ errorMessageId | translate }} + + } - - {{ errorMessageId | translate }} - + @if (!isProcessDefinitionsEmpty) { +
+
+ @if (showSelectProcessDropdown) { + + {{ + 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.LABEL.TYPE' | translate + }} + -
- - - {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.LABEL.TYPE' | translate }} - - -
- - +
+ + {{ getProcessDefinitionValue(processDef) }} - - + + - + +
+ @if (processDefinition.hasError('required')) { + + {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.PROCESS_DEFINITION_REQUIRED' | translate }} + + } + + } -
- - {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.PROCESS_DEFINITION_REQUIRED' | translate }} - -
+ + + {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.LABEL.NAME' | translate }} + - - - {{'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.LABEL.NAME' | translate}} - + + @if (processInstanceName.hasError('required')) { + + {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.PROCESS_NAME_REQUIRED' | translate }} + + } + @if (processInstanceName.hasError('maxlength')) { + + {{ + 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.MAXIMUM_LENGTH' + | translate: { characters: maxNameLength } + }} + + } + @if (processInstanceName.hasError('pattern')) { + + {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.SPACE_VALIDATOR' | translate }} + + } + + + - - - {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.PROCESS_NAME_REQUIRED' | translate }} - - - {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.MAXIMUM_LENGTH' | translate : { characters : maxNameLength } }} - - - {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.SPACE_VALIDATOR' | translate }} - - - - - - - - - - - - -
- - - - + @if (hasForm) { + + + + + + } @else { + + } +
+ } @else { + @if (processDefinitionLoaded) { + + + {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.NO_PROCESS_DEFINITIONS' | translate | uppercase }} + + + } + } +
+
+} @else { +
+ +
+}
- - + } + @if (showStartProcessButton$ | async) { + -
-
- - - - - {{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.NO_PROCESS_DEFINITIONS' | translate | uppercase}} - - - - - -
- + + }
diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.scss b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.scss index e62a2151fe..766d4920c7 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.scss +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.scss @@ -19,6 +19,10 @@ padding-bottom: 1.25em; } + &-error-message { + padding-left: 0.5em; + } + &-process-input-container { margin: 0 7px; } diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts index 6d262cdcc5..9f37ffc48d 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts @@ -877,7 +877,13 @@ describe('StartProcessCloudComponent', () => { it('should throw error event when process cannot be started', async () => { const errorSpy = spyOn(component.error, 'emit'); - const error = { message: 'My error' }; + const error = { + response: { + body: { + message: 'My error' + } + } + }; startProcessSpy = startProcessSpy.and.returnValue(throwError(error)); component.startProcess(); await fixture.whenStable(); @@ -888,14 +894,21 @@ describe('StartProcessCloudComponent', () => { getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); const change = new SimpleChange('myApp', 'myApp1', true); component.ngOnChanges({ appName: change }); - startProcessSpy = startProcessSpy.and.returnValue(throwError({})); + const error = { + response: { + body: { + message: 'Process start failed' + } + } + }; + startProcessSpy = startProcessSpy.and.returnValue(throwError(error)); component.startProcess(); fixture.detectChanges(); await fixture.whenStable(); const errorEl = fixture.nativeElement.querySelector('#error-message'); - expect(errorEl.innerText.trim()).toBe('ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.START'); + expect(errorEl.innerText.trim()).toBe('Process start failed'); }); it('should emit start event when start select a process and add a name', (done) => { diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts index 402a8281b6..504c7ca6b6 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts @@ -70,6 +70,7 @@ const PROCESS_DEFINITION_IDENTIFIER_REG_EXP = new RegExp('%{processdefinition}', @Component({ selector: 'adf-cloud-start-process', + standalone: true, imports: [ CommonModule, TranslatePipe, @@ -456,8 +457,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit { this.isProcessStarting = false; }, error: (err) => { - this.errorMessageId = 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.START'; - this.unifyErrorResponse(err); + this.errorMessageId = err?.response?.body?.message || 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.START_PROCESS'; this.error.emit(err); this.isProcessStarting = false; } @@ -483,14 +483,6 @@ export class StartProcessCloudComponent implements OnChanges, OnInit { } } - private unifyErrorResponse(err: any) { - if (!err?.response?.body?.entry && err?.response?.body?.message) { - err.response.body = { - entry: JSON.parse(err.response.body.message) - }; - } - } - cancelStartProcess() { this.cancel.emit(); }