Skip to content

Commit

Permalink
Catch any possible exception when calling JSON.parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
MasoudFallahpourbaee committed Apr 26, 2024
1 parent 7f8542a commit e9ed4a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/KlarnaCheckoutView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ export class KlarnaCheckoutView extends Component<
}>
>
) => {
let params = {};
try {
params = JSON.parse(event.nativeEvent.productEvent.params);
} catch (e) {
console.error('Failed to parse productEvent.params', e);
}
const productEvent: KlarnaProductEvent = {
action: event.nativeEvent.productEvent.action,
params: JSON.parse(event.nativeEvent.productEvent.params),
params: params,
};
this.props.onEvent?.(productEvent);
}}
Expand Down

0 comments on commit e9ed4a8

Please sign in to comment.