mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 14:05:24 +02:00
chore: enable verbose error logging on experiment calculations to reveal silent production errors
This commit is contained in:
@@ -85,6 +85,7 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
|
||||
if (req.method === 'PUT') {
|
||||
const { id } = req.query;
|
||||
const updates = req.body;
|
||||
console.log('Update payload for id', id, ':', updates);
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('experiments')
|
||||
|
||||
@@ -55,9 +55,12 @@ const ExperimentDetail: React.FC<ExperimentDetailProps> = ({ experimentId, onClo
|
||||
setLoading(true);
|
||||
try {
|
||||
const perf = await calculateExperimentPerformance(experiment, salesData);
|
||||
console.log('Calculation yielded performance delta payload:', perf);
|
||||
const updated = await updateExperiment(experiment.id, perf);
|
||||
console.log('Update return from backend:', updated);
|
||||
setExperiment(updated);
|
||||
} catch (e: any) {
|
||||
console.error('Full calculation error:', e);
|
||||
alert(`Error calculating results: ${e.message}`);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
+19
-10
@@ -59,18 +59,27 @@ export const updateExperiment = async (
|
||||
id: string,
|
||||
updates: Partial<Experiment>
|
||||
): Promise<Experiment> => {
|
||||
const response = await fetch(`${API_BASE}?id=${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(updates),
|
||||
});
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}?id=${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(updates),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.error || 'Failed to update experiment');
|
||||
if (!response.ok) {
|
||||
let errText = await response.text();
|
||||
try {
|
||||
const errJson = JSON.parse(errText);
|
||||
errText = errJson.error || errText;
|
||||
} catch (e) { }
|
||||
throw new Error(errText);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (err: any) {
|
||||
console.error('API Error in updateExperiment:', err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const deleteExperiment = async (id: string): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user