diff --git a/apps/web/src/components/ErrorBoundary.tsx b/apps/web/src/components/ErrorBoundary.tsx new file mode 100644 index 0000000..574c0a9 --- /dev/null +++ b/apps/web/src/components/ErrorBoundary.tsx @@ -0,0 +1,73 @@ +import React, { Component, ErrorInfo, ReactNode } from 'react'; +import { getUserFriendlyMessage } from '@brazil-swift-ops/utils'; + +interface Props { + children: ReactNode; + fallback?: ReactNode; +} + +interface State { + hasError: boolean; + error: Error | null; +} + +export class ErrorBoundary extends Component { + public state: State = { + hasError: false, + error: null, + }; + + public static getDerivedStateFromError(error: Error): State { + return { hasError: true, error }; + } + + public componentDidCatch(error: Error, errorInfo: ErrorInfo) { + console.error('ErrorBoundary caught an error:', error, errorInfo); + } + + public render() { + if (this.state.hasError) { + if (this.props.fallback) { + return this.props.fallback; + } + + return ( +
+
+
+ + + +
+

+ Something went wrong +

+

+ {this.state.error + ? getUserFriendlyMessage(this.state.error) + : 'An unexpected error occurred'} +

+ +
+
+ ); + } + + return this.props.children; + } +} diff --git a/packages/iso20022/src/exporter.ts b/packages/iso20022/src/exporter.ts index e15d445..7a7e750 100644 --- a/packages/iso20022/src/exporter.ts +++ b/packages/iso20022/src/exporter.ts @@ -1,6 +1,6 @@ -import type { ISO20022Message } from '@brazil-swift-ops/types'; +import type { ISO20022Message, Pacs008Message, Pacs009Message, CreditTransferTransaction } from '@brazil-swift-ops/types'; import { create } from 'xmlbuilder2'; -import { formatISO20022DateTime } from '@brazil-swift-ops/utils'; +import { formatISO20022DateTime, formatISO20022Date } from '@brazil-swift-ops/utils'; export function exportToJSON(message: ISO20022Message): string { return JSON.stringify(message, null, 2); @@ -132,7 +132,7 @@ export function exportToXML(message: ISO20022Message): string { Array.isArray(pacsMessage.creditTransferTransaction) && pacsMessage.creditTransferTransaction.length > 0 ) { - pacsMessage.creditTransferTransaction.forEach((ctt) => { + pacsMessage.creditTransferTransaction.forEach((ctt: CreditTransferTransaction) => { const cdtTrfTx = root.ele('CdtTrfTx'); if (ctt.paymentIdentification) { const pmtId = cdtTrfTx.ele('PmtId'); diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index fc119f6..9c70c11 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -10,3 +10,4 @@ export * from './validation'; export * from './input-validation'; export * from './eo-uplift'; export * from './institution-config'; +export * from './errors';