mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
Removes unnecessary error handling method
Removes the `unifyErrorResponse` method as it's no longer needed. Updates error handling logic to directly use the error message from the response body. This simplifies the error processing and avoids unnecessary parsing.
This commit is contained in:
@@ -877,7 +877,13 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
|
|
||||||
it('should throw error event when process cannot be started', async () => {
|
it('should throw error event when process cannot be started', async () => {
|
||||||
const errorSpy = spyOn(component.error, 'emit');
|
const errorSpy = spyOn(component.error, 'emit');
|
||||||
const error = { message: 'My error' };
|
const error = {
|
||||||
|
response: {
|
||||||
|
body: {
|
||||||
|
message: 'My error'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
startProcessSpy = startProcessSpy.and.returnValue(throwError(error));
|
startProcessSpy = startProcessSpy.and.returnValue(throwError(error));
|
||||||
component.startProcess();
|
component.startProcess();
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
@@ -888,14 +894,21 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions));
|
getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions));
|
||||||
const change = new SimpleChange('myApp', 'myApp1', true);
|
const change = new SimpleChange('myApp', 'myApp1', true);
|
||||||
component.ngOnChanges({ appName: change });
|
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();
|
component.startProcess();
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
|
|
||||||
const errorEl = fixture.nativeElement.querySelector('#error-message');
|
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) => {
|
it('should emit start event when start select a process and add a name', (done) => {
|
||||||
|
@@ -458,7 +458,6 @@ export class StartProcessCloudComponent implements OnChanges, OnInit {
|
|||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
this.errorMessageId = err?.response?.body?.message || 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.START_PROCESS';
|
this.errorMessageId = err?.response?.body?.message || 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.START_PROCESS';
|
||||||
this.unifyErrorResponse(err);
|
|
||||||
this.error.emit(err);
|
this.error.emit(err);
|
||||||
this.isProcessStarting = false;
|
this.isProcessStarting = false;
|
||||||
}
|
}
|
||||||
@@ -484,19 +483,6 @@ export class StartProcessCloudComponent implements OnChanges, OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private unifyErrorResponse(err: any) {
|
|
||||||
if (!err?.response?.body?.entry && err?.response?.body?.message) {
|
|
||||||
try {
|
|
||||||
err.response.body.entry = JSON.parse(err.response.body.message);
|
|
||||||
} catch (jsonError) {
|
|
||||||
console.warn('Failed to parse error message as JSON:', jsonError);
|
|
||||||
err.response.body.entry = {
|
|
||||||
message: err.response.body.message
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cancelStartProcess() {
|
cancelStartProcess() {
|
||||||
this.cancel.emit();
|
this.cancel.emit();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user