From e674378080be7de7846a1f5088bf7818b289bec4 Mon Sep 17 00:00:00 2001 From: Lorenz Hilpert Date: Mon, 14 Jul 2025 14:57:41 +0000 Subject: [PATCH] Merged PR 1883: fix(return-details): update email validation and improve error handling fix(return-details): update email validation and improve error handling Refs: #5211 --- .github/instructions/nx.instructions.md | 12 ++++- .../src/app/providers/isa.error-handler.ts | 36 ++++++++----- .../src/app/providers/isa.log-provider.ts | 50 +++++++++++-------- apps/isa-app/src/core/logger/log.provider.ts | 3 +- .../lib/services/return-details.service.ts | 2 +- .../src/lib/return-details.component.html | 2 +- .../src/lib/return-details.component.ts | 15 ++++-- 7 files changed, 76 insertions(+), 44 deletions(-) diff --git a/.github/instructions/nx.instructions.md b/.github/instructions/nx.instructions.md index 4af8bc88b..b00e68d1d 100644 --- a/.github/instructions/nx.instructions.md +++ b/.github/instructions/nx.instructions.md @@ -4,7 +4,7 @@ applyTo: '**' // This file is automatically generated by Nx Console -You are in an nx workspace using Nx 20.4.6 and npm as the package manager. +You are in an nx workspace using Nx 21.2.1 and npm as the package manager. You have access to the Nx MCP server and the tools it provides. Use them. Follow these guidelines in order to best help the user: @@ -27,6 +27,14 @@ If the user wants to generate something, use the following flow: - wait for the user to finish the generator - read the generator log file using the 'nx_read_generator_log' tool - use the information provided in the log file to answer the user's question or continue with what they were doing -undefined + +# Running Tasks Guidelines +If the user wants help with tasks or commands (which include keywords like "test", "build", "lint", or other similar actions), use the following flow: +- Use the 'nx_current_running_tasks_details' tool to get the list of tasks (this can include tasks that were completed, stopped or failed). +- If there are any tasks, ask the user if they would like help with a specific task then use the 'nx_current_running_task_output' tool to get the terminal output for that task/command +- Use the terminal output from 'nx_current_running_task_output' to see what's wrong and help the user fix their problem. Use the appropriate tools if necessary +- If the user would like to rerun the task or command, always use `nx run ` to rerun in the terminal. This will ensure that the task will run in the nx context and will be run the same way it originally executed +- If the task was marked as "continuous" do not offer to rerun the task. This task is already running and the user can see the output in the terminal. You can use 'nx_current_running_task_output' to get the output of the task to verify the output. + diff --git a/apps/isa-app/src/app/providers/isa.error-handler.ts b/apps/isa-app/src/app/providers/isa.error-handler.ts index cd5d67acd..5f6210520 100644 --- a/apps/isa-app/src/app/providers/isa.error-handler.ts +++ b/apps/isa-app/src/app/providers/isa.error-handler.ts @@ -1,11 +1,16 @@ -import { HttpErrorResponse } from '@angular/common/http'; -import { ErrorHandler, Injectable } from '@angular/core'; -import { AuthService } from '@core/auth'; -import { DialogModel, UiDialogModalComponent, UiErrorModalComponent, UiModalService } from '@ui/modal'; -import { IsaLogProvider } from './isa.log-provider'; -import { LogLevel } from '@core/logger'; +import { HttpErrorResponse } from "@angular/common/http"; +import { ErrorHandler, Injectable } from "@angular/core"; +import { AuthService } from "@core/auth"; +import { + DialogModel, + UiDialogModalComponent, + UiErrorModalComponent, + UiModalService, +} from "@ui/modal"; +import { IsaLogProvider } from "./isa.log-provider"; +import { LogLevel } from "@core/logger"; -@Injectable({ providedIn: 'root' }) +@Injectable({ providedIn: "root" }) export class IsaErrorHandler implements ErrorHandler { constructor( private _modal: UiModalService, @@ -17,7 +22,7 @@ export class IsaErrorHandler implements ErrorHandler { console.error(error); // Bei Klick auf Abbrechen auf der Login Seite erneut zur Login Seite weiterleiten - if (error?.type === 'token_error') { + if (error?.type === "token_error") { this._authService.login(); return; } @@ -26,11 +31,14 @@ export class IsaErrorHandler implements ErrorHandler { await this._modal .open({ content: UiDialogModalComponent, - title: 'Sitzung abgelaufen', + title: "Sitzung abgelaufen", data: { handleCommand: false, - content: 'Sie waren zu lange nicht in der ISA aktiv. Bitte melden Sie sich erneut an', - actions: [{ command: 'CLOSE', selected: true, label: 'Erneut anmelden' }], + content: + "Sie waren zu lange nicht in der ISA aktiv. Bitte melden Sie sich erneut an", + actions: [ + { command: "CLOSE", selected: true, label: "Erneut anmelden" }, + ], } as DialogModel, }) .afterClosed$.toPromise(); @@ -39,7 +47,11 @@ export class IsaErrorHandler implements ErrorHandler { return; } - this._isaLogProvider.log(LogLevel.ERROR, 'Client Error', error); + try { + this._isaLogProvider.log(LogLevel.ERROR, "Client Error", error); + } catch (logError) { + console.error("Error logging to IsaLogProvider:", logError); + } // this._modal.open({ // content: UiErrorModalComponent, diff --git a/apps/isa-app/src/app/providers/isa.log-provider.ts b/apps/isa-app/src/app/providers/isa.log-provider.ts index cbe728730..668eebc1c 100644 --- a/apps/isa-app/src/app/providers/isa.log-provider.ts +++ b/apps/isa-app/src/app/providers/isa.log-provider.ts @@ -1,28 +1,36 @@ -import { Injectable, Injector } from '@angular/core'; -import { LogLevel, LogProvider } from '@core/logger'; -import { UserStateService } from '@generated/swagger/isa-api'; -import { environment } from '../../environments/environment'; +import { Injectable } from "@angular/core"; +import { LogLevel, LogProvider } from "@core/logger"; +import { UserStateService } from "@generated/swagger/isa-api"; +import { environment } from "../../environments/environment"; -@Injectable({ providedIn: 'root' }) +@Injectable({ providedIn: "root" }) export class IsaLogProvider implements LogProvider { static InfoService: UserStateService | undefined; - constructor() {} - - log(logLevel: LogLevel, message: string, error: Error, ...optionalParams: any[]): void { - if (!environment.production && (logLevel === LogLevel.WARN || logLevel === LogLevel.ERROR)) { - IsaLogProvider.InfoService?.UserStateSaveLog({ - logType: logLevel, - message: message, - content: JSON.stringify({ - error: error?.name, - message: error?.message, - stack: error?.stack, - data: optionalParams, - }), - }) - .toPromise() - .catch(() => {}); + log( + logLevel: LogLevel, + message: string, + error: Error, + ...optionalParams: any[] + ): void { + try { + if ( + !environment.production && + (logLevel === LogLevel.WARN || logLevel === LogLevel.ERROR) + ) { + IsaLogProvider.InfoService?.UserStateSaveLog({ + logType: logLevel, + message: message, + content: JSON.stringify({ + error: error?.name, + message: error?.message, + stack: error?.stack, + data: optionalParams, + }), + }).toPromise(); + } + } catch (error) { + console.error("Error logging to InfoService:", error); } } } diff --git a/apps/isa-app/src/core/logger/log.provider.ts b/apps/isa-app/src/core/logger/log.provider.ts index e66f74464..303535616 100644 --- a/apps/isa-app/src/core/logger/log.provider.ts +++ b/apps/isa-app/src/core/logger/log.provider.ts @@ -1,5 +1,4 @@ -import { Injectable } from '@angular/core'; -import { LogLevel } from './log-level'; +import { LogLevel } from "./log-level"; export interface LogProvider { log(logLevel: LogLevel, message: string, ...optionalParams: any[]): void; diff --git a/libs/oms/data-access/src/lib/services/return-details.service.ts b/libs/oms/data-access/src/lib/services/return-details.service.ts index 161566ccf..cb658a5cc 100644 --- a/libs/oms/data-access/src/lib/services/return-details.service.ts +++ b/libs/oms/data-access/src/lib/services/return-details.service.ts @@ -116,7 +116,7 @@ export class ReturnDetailsService { * Validates that the email parameter is a properly formatted email address. */ static FetchReceiptsEmailParamsSchema = z.object({ - email: z.string().email(), + email: z.string(), }); /** diff --git a/libs/oms/feature/return-details/src/lib/return-details.component.html b/libs/oms/feature/return-details/src/lib/return-details.component.html index d03394bed..36c7b37db 100644 --- a/libs/oms/feature/return-details/src/lib/return-details.component.html +++ b/libs/oms/feature/return-details/src/lib/return-details.component.html @@ -22,7 +22,7 @@ > @if (customerReceiptsResource.isLoading()) { - } @else { + } @else if (!customerReceiptsResource.error()) { @for (receipt of customerReceiptsResource.value(); track receipt.id) { @if (r.id !== receipt.id) { { - console.log("Fetching customer receipts for:", request); const email = request?.buyer?.communicationDetails?.email; if (!email) { return []; } - return await this.#returnDetailsService.fetchReceiptsByEmail( - { email }, - abortSignal, - ); + + try { + return await this.#returnDetailsService.fetchReceiptsByEmail( + { email }, + abortSignal, + ); + } catch (error) { + this.#logger.error("Failed to fetch customer receipts", error); + return []; + } }, });