Improve error extraction in AuthContext.updateProfile
cgen-e18475d3240f4393bdc0d8a65ff14d10
This commit is contained in:
parent
bfaaed46a5
commit
22084284cc
1 changed files with 14 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue