fixed Next configiration

This commit is contained in:
Dmitri 2026-03-24 16:10:54 +04:00
parent 9159f467f5
commit 4166e37a93
2 changed files with 9 additions and 68 deletions

View File

@ -34,6 +34,11 @@ const nextConfig = {
hostname: '**',
},
],
localPatterns: [
{
pathname: '/api/**',
},
],
},
};

View File

@ -47,19 +47,13 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
}
}
async componentWillUnmount() {
componentWillUnmount() {
if (process.env.NODE_ENV !== 'production') {
logger.debug('componentWillUnmount');
const response = await fetch('/api/logError', {
method: 'DELETE',
});
const data = await response.json();
logger.debug('Error logs cleared:', data);
}
}
async componentDidCatch(error: Error, errorInfo: ErrorInfo) {
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
// Update state with error details (always needed for UI)
this.setState({
errorInfo: errorInfo,
@ -68,47 +62,6 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
// Only perform logging in non-production environments
if (process.env.NODE_ENV !== 'production') {
logger.info('Error caught in boundary:', { error, errorInfo });
// Function to log errors to the server
const logErrorToServer = async () => {
try {
const response = await fetch('/api/logError', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: error.message,
stack: errorInfo.componentStack,
}),
});
const data = await response.json();
logger.debug('Error logged:', data);
} catch (err) {
logger.error(
'Failed to log error:',
err instanceof Error ? err : { error: err },
);
}
};
// Function to fetch logged errors (optional)
const fetchLoggedErrors = async () => {
try {
const response = await fetch('/api/logError');
const data = await response.json();
logger.debug('Fetched logs:', data);
} catch (err) {
logger.error(
'Failed to fetch logs:',
err instanceof Error ? err : { error: err },
);
}
};
await logErrorToServer();
await fetchLoggedErrors();
}
}
@ -127,25 +80,8 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
});
};
tryAgain = async () => {
// Only clear error logs in non-production environments
if (process.env.NODE_ENV !== 'production') {
try {
const response = await fetch('/api/logError', {
method: 'DELETE',
});
const data = await response.json();
logger.debug('Error logs cleared:', data);
} catch (e) {
logger.error(
'Failed to clear error logs:',
e instanceof Error ? e : { error: e },
);
}
}
// Always reset the error state (needed for UI recovery)
tryAgain = () => {
// Reset the error state (needed for UI recovery)
this.setState({ hasError: false });
};