mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 1948: fix(remission-error): simplify error handling in remission components
fix(remission-error): simplify error handling in remission components Refactor error handling to use consistent error message extraction pattern. Remove dependency on ResponseArgsError type and streamline error processing in both RemissionListComponent and RemissionReturnReceiptDetailsItemComponent. Extract error handling logic into separate methods for better maintainability. Ref: #5331
This commit is contained in:
committed by
Lorenz Hilpert
parent
fd693a4beb
commit
c672ae4012
@@ -42,7 +42,6 @@ import {
|
||||
getStockToRemit,
|
||||
RemissionListType,
|
||||
RemissionResponseArgsErrorMessage,
|
||||
RemissionResponseArgsErrorMessageValue,
|
||||
} from '@isa/remission/data-access';
|
||||
import { injectDialog, injectFeedbackErrorDialog } from '@isa/ui/dialog';
|
||||
import { SearchItemToRemitDialogComponent } from '@isa/remission/shared/search-item-to-remit-dialog';
|
||||
@@ -52,7 +51,6 @@ import { RemissionProcessedHintComponent } from './remission-processed-hint/remi
|
||||
import { RemissionListDepartmentElementsComponent } from './remission-list-department-elements/remission-list-department-elements.component';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import { RemissionListEmptyStateComponent } from './remission-list-empty-state/remission-list-empty-state.component';
|
||||
import { ResponseArgsError } from '@isa/common/data-access';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
function querySettingsFactory() {
|
||||
@@ -516,7 +514,7 @@ export class RemissionListComponent {
|
||||
}
|
||||
this.remitItemsState.set('success');
|
||||
this.reloadListAndReturnData();
|
||||
} catch (error: ResponseArgsError<unknown> | Error | unknown) {
|
||||
} catch (error) {
|
||||
await this.handleRemitItemsError(error);
|
||||
}
|
||||
|
||||
@@ -556,43 +554,37 @@ export class RemissionListComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles errors that occur during the remission of items.
|
||||
* Logs the error, sets the error message signal, and displays an error dialog if applicable.
|
||||
* Handles errors that occur during the remission of items.
|
||||
* Logs the error, displays an error dialog, and reloads the list and return data.
|
||||
* If the error indicates that the remission is already completed, it clears the remission state.
|
||||
* Finally, it reloads the remission list and return data.
|
||||
* @param error - The error that occurred during the remission process.
|
||||
* Can be a ResponseArgsError, a generic Error, or any other unknown type.
|
||||
* @returns A promise that resolves when error handling is complete.
|
||||
* Sets the stateful button to 'error' to indicate the failure.
|
||||
* @param error - The error object caught during the remission process.
|
||||
* @returns A promise that resolves when the error handling is complete.
|
||||
*/
|
||||
async handleRemitItemsError(
|
||||
error: ResponseArgsError<unknown> | Error | unknown,
|
||||
) {
|
||||
async handleRemitItemsError(error: any) {
|
||||
this.#logger.error('Failed to remit items', error);
|
||||
this.remitItemsError.set(
|
||||
error instanceof Error || error instanceof ResponseArgsError
|
||||
? error.message
|
||||
: 'Artikel konnten nicht remittiert werden',
|
||||
|
||||
const errorMessage =
|
||||
error?.error?.message ??
|
||||
error?.message ??
|
||||
'Artikel konnten nicht remittiert werden';
|
||||
|
||||
this.remitItemsError.set(errorMessage);
|
||||
|
||||
await firstValueFrom(
|
||||
this.errorDialog({
|
||||
data: {
|
||||
errorMessage,
|
||||
},
|
||||
}).closed,
|
||||
);
|
||||
|
||||
if (error instanceof ResponseArgsError) {
|
||||
const errorMessage = (error?.responseArgs?.message ??
|
||||
error?.message) as RemissionResponseArgsErrorMessageValue;
|
||||
|
||||
await firstValueFrom(
|
||||
this.errorDialog({
|
||||
data: {
|
||||
errorMessage,
|
||||
},
|
||||
}).closed,
|
||||
);
|
||||
|
||||
if (errorMessage === RemissionResponseArgsErrorMessage.AlreadyCompleted) {
|
||||
this.#store.clearState();
|
||||
}
|
||||
|
||||
this.reloadListAndReturnData();
|
||||
if (errorMessage === RemissionResponseArgsErrorMessage.AlreadyCompleted) {
|
||||
this.#store.clearState();
|
||||
}
|
||||
|
||||
this.reloadListAndReturnData();
|
||||
|
||||
this.remitItemsState.set('error'); // Stateful-Button auf Error setzen
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import { provideIcons } from '@ng-icons/core';
|
||||
import { isaActionClose } from '@isa/icons';
|
||||
import { logger } from '@isa/core/logging';
|
||||
import { injectFeedbackErrorDialog } from '@isa/ui/dialog';
|
||||
import { ResponseArgsError } from '@isa/common/data-access';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
/**
|
||||
@@ -104,25 +103,25 @@ export class RemissionReturnReceiptDetailsItemComponent {
|
||||
returnId: this.returnId(),
|
||||
receiptItemId: this.item().id,
|
||||
});
|
||||
} catch (error: ResponseArgsError<unknown> | Error | unknown) {
|
||||
this.#logger.error('Failed to remove item', error);
|
||||
|
||||
if (error instanceof ResponseArgsError) {
|
||||
const errorMessage =
|
||||
error?.responseArgs?.message ??
|
||||
error?.message ??
|
||||
RemissionResponseArgsErrorMessage.AlreadyRemoved;
|
||||
|
||||
await firstValueFrom(
|
||||
this.errorDialog({
|
||||
data: {
|
||||
errorMessage,
|
||||
},
|
||||
}).closed,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
await this.handleRemoveItemError(error);
|
||||
}
|
||||
this.reloadReturn.emit();
|
||||
this.removing.set(false);
|
||||
}
|
||||
|
||||
async handleRemoveItemError(error: any) {
|
||||
this.#logger.error('Failed to remove item', error);
|
||||
|
||||
const errorMessage =
|
||||
error?.error?.message ?? RemissionResponseArgsErrorMessage.AlreadyRemoved;
|
||||
|
||||
await firstValueFrom(
|
||||
this.errorDialog({
|
||||
data: {
|
||||
errorMessage,
|
||||
},
|
||||
}).closed,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user