From 16e69743dbed35d947b862af5752c65daff173d8 Mon Sep 17 00:00:00 2001 From: Sampo Tawast Date: Thu, 5 Dec 2024 15:25:19 +0200 Subject: [PATCH] fix: try to parse all kinds of ahjo errors --- .../applicationList/ApplicationList.tsx | 21 ++++++++++++------- .../benefit/shared/src/types/application.d.ts | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/frontend/benefit/handler/src/components/applicationList/ApplicationList.tsx b/frontend/benefit/handler/src/components/applicationList/ApplicationList.tsx index 98b9ac6ce4..01b6da59d9 100644 --- a/frontend/benefit/handler/src/components/applicationList/ApplicationList.tsx +++ b/frontend/benefit/handler/src/components/applicationList/ApplicationList.tsx @@ -109,6 +109,19 @@ export const renderPaymentTagPerStatus = ( ); +const parseAhjoError = (ahjoError: AhjoError): JSX.Element[] => { + if (Array.isArray(ahjoError.errorFromAhjo)) + return ahjoError.errorFromAhjo.map(({ message }) =>
  • {message}
  • ); + + if ( + typeof ahjoError.errorFromAhjo === 'object' && + ahjoError.errorFromAhjo.message + ) + return [
  • {ahjoError.errorFromAhjo.message}
  • ]; + + return [
  • {String(ahjoError.errorFromAhjo)}
  • ]; +}; + const ApplicationList: React.FC = ({ heading, status, @@ -177,13 +190,7 @@ const ApplicationList: React.FC = ({ Ahjo, {convertToUIDateAndTimeFormat(ahjoError?.modifiedAt)} -
      - {ahjoError?.errorFromAhjo?.map - ? ahjoError?.errorFromAhjo?.map(({ message }) => ( -
    • {message}
    • - )) - : ahjoError?.errorFromAhjo} -
    +
      {parseAhjoError(ahjoError)}
    )} diff --git a/frontend/benefit/shared/src/types/application.d.ts b/frontend/benefit/shared/src/types/application.d.ts index a0e36d73b3..9db4e7c6d4 100644 --- a/frontend/benefit/shared/src/types/application.d.ts +++ b/frontend/benefit/shared/src/types/application.d.ts @@ -266,13 +266,13 @@ export interface DecisionProposalDraft { } export interface AhjoError { - errorFromAhjo: ErrorFromAhjo[]; + errorFromAhjo: ErrorFromAhjo | ErrorFromAhjo[]; modifiedAt: string; status: string; } export interface AhjoErrorData { - error_from_ahjo: ErrorFromAhjo[]; + error_from_ahjo: ErrorFromAhjo | ErrorFromAhjo[]; modified_at: string; status: string; }