fixed Next configiration
This commit is contained in:
parent
9159f467f5
commit
4166e37a93
@ -34,6 +34,11 @@ const nextConfig = {
|
|||||||
hostname: '**',
|
hostname: '**',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
localPatterns: [
|
||||||
|
{
|
||||||
|
pathname: '/api/**',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -47,19 +47,13 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
logger.debug('componentWillUnmount');
|
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)
|
// Update state with error details (always needed for UI)
|
||||||
this.setState({
|
this.setState({
|
||||||
errorInfo: errorInfo,
|
errorInfo: errorInfo,
|
||||||
@ -68,47 +62,6 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|||||||
// Only perform logging in non-production environments
|
// Only perform logging in non-production environments
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
logger.info('Error caught in boundary:', { error, errorInfo });
|
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 () => {
|
tryAgain = () => {
|
||||||
// Only clear error logs in non-production environments
|
// Reset the error state (needed for UI recovery)
|
||||||
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)
|
|
||||||
this.setState({ hasError: false });
|
this.setState({ hasError: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user