Improve error extraction in AuthContext.updateProfile

cgen-e18475d3240f4393bdc0d8a65ff14d10
This commit is contained in:
Builder.io 2025-10-14 03:56:27 +00:00
parent bfaaed46a5
commit 22084284cc

View file

@ -713,11 +713,23 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
});
} catch (error: any) {
setProfile((prev) => ({ ...(prev || ({} as any)), ...updates }) as any);
const extractErrorMessage = (err: any) => {
if (!err) return "Failed to update profile. Please try again.";
if (typeof err === "string") return err;
if (err.message) return err.message;
try {
return JSON.stringify(err);
} catch (e) {
return String(err);
}
};
const msg = extractErrorMessage(error);
aethexToast.error({
title: "Update failed",
description: error.message,
description: msg,
});
throw error;
// Throw a normalized Error to give callers a searchable message
throw new Error(msg);
}
};