Skip to content

Commit

Permalink
chore: improve serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoMolinari95 committed Mar 3, 2025
1 parent 9c80283 commit c2d3b8f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
17 changes: 12 additions & 5 deletions ts/features/itwallet/common/utils/itwStoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ export const pollForStoreValue = <T>({
*/
export const serializeFailureReason = (
failure: IssuanceFailure | CredentialIssuanceFailure | RemoteFailure
) => ({
...failure,
reason:
failure.reason instanceof Error ? failure.reason.message : failure.reason
});
) => {
const reason = !failure.reason
? "Reason not provided"
: failure.reason instanceof Error
? failure.reason.message
: failure.reason;

return {
...failure,
reason
};
};
13 changes: 10 additions & 3 deletions ts/features/itwallet/issuance/hooks/useEidEventsTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ export const useEidEventsTracking = ({ failure, identification }: Params) => {

if (failure.type === IssuanceFailureType.UNEXPECTED) {
/*
* Some errors have an empty object as `failure.reason`, but `failure.reason.message` is still defined.
* In these cases, we use the `serializeFailureReason` function to provide a more informative message on Mixpanel.
* We handle two cases here:
* 1. If failure.reason is undefined/null, we serialize the failure to provide a default message with "Reason not provided".
* 2. If failure.reason is an empty object with no keys, we serialize it to extract message property.
* To maintain compatibility with the existing failure tracking, we keep the original `failure` object when `failure.reason` is not empty.
*/
if (!failure.reason) {
return trackItwIdRequestUnexpectedFailure(
serializeFailureReason(failure)
);
}
return trackItwIdRequestUnexpectedFailure(
!failure.reason || Object.keys(failure.reason as object).length === 0
typeof failure.reason === "object" &&
Object.keys(failure.reason).length === 0
? serializeFailureReason(failure)
: failure
);
Expand Down

0 comments on commit c2d3b8f

Please sign in to comment.