Fix build errors - add ErrorBoundary component and export errors from utils

This commit is contained in:
defiQUG
2026-01-23 16:34:52 -08:00
parent 7558268f9d
commit 8322c8bf28
3 changed files with 77 additions and 3 deletions

View File

@@ -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<Props, State> {
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 (
<div className="min-h-screen flex items-center justify-center bg-gray-50">
<div className="max-w-md w-full bg-white shadow-lg rounded-lg p-6">
<div className="flex items-center justify-center w-12 h-12 mx-auto bg-red-100 rounded-full">
<svg
className="w-6 h-6 text-red-600"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
/>
</svg>
</div>
<h2 className="mt-4 text-lg font-semibold text-gray-900 text-center">
Something went wrong
</h2>
<p className="mt-2 text-sm text-gray-600 text-center">
{this.state.error
? getUserFriendlyMessage(this.state.error)
: 'An unexpected error occurred'}
</p>
<button
onClick={() => window.location.reload()}
className="mt-4 w-full bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 transition"
>
Reload Page
</button>
</div>
</div>
);
}
return this.props.children;
}
}

View File

@@ -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');

View File

@@ -10,3 +10,4 @@ export * from './validation';
export * from './input-validation';
export * from './eo-uplift';
export * from './institution-config';
export * from './errors';