Skip to content

Commit

Permalink
fix(react): safely access caught Error properties (#3196)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdvl authored Sep 8, 2021
1 parent 8747fbe commit 8dbbec4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ export default function DescriptionField({
await onUpdate(desc || '');
// message.destroy();
// message.success({ content: 'Updated!', duration: 2 });
} catch (e) {
} catch (e: unknown) {
message.destroy();
message.error({ content: `Update Failed! \n ${e.message || ''}`, duration: 2 });
if (e instanceof Error) message.error({ content: `Update Failed! \n ${e.message || ''}`, duration: 2 });
}
onCloseModal();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export default function UpdatableDescription({
entityUrn: urn,
});
message.success({ content: 'Updated!', duration: 2 });
} catch (e) {
} catch (e: unknown) {
message.destroy();
message.error({ content: `Update Failed! \n ${e.message || ''}`, duration: 2 });
if (e instanceof Error) message.error({ content: `Update Failed! \n ${e.message || ''}`, duration: 2 });
}
setShowAddDescModal(false);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export const AddLinkModal = ({ buttonProps }: { buttonProps?: Record<string, unk
variables: { input: { urn, institutionalMemory: { elements: newLinks } } },
});
message.success({ content: 'Link Added', duration: 2 });
} catch (e) {
} catch (e: unknown) {
message.destroy();
message.error({ content: `Failed to add link: \n ${e.message || ''}`, duration: 3 });
if (e instanceof Error) {
message.error({ content: `Failed to add link: \n ${e.message || ''}`, duration: 3 });
}
}

handleClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ export const DescriptionEditor = ({ onComplete }: { onComplete?: () => void }) =
});
message.success({ content: 'Description Updated', duration: 2 });
if (onComplete) onComplete();
} catch (e) {
} catch (e: unknown) {
message.destroy();
message.error({ content: `Failed to update description: \n ${e.message || ''}`, duration: 2 });
if (e instanceof Error) {
message.error({ content: `Failed to update description: \n ${e.message || ''}`, duration: 2 });
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export const LinkList = () => {
variables: { input: { urn, institutionalMemory: { elements: newLinks } } },
});
message.success({ content: 'Link Deleted', duration: 2 });
} catch (e) {
} catch (e: unknown) {
message.destroy();
message.error({ content: `Error deleting link: \n ${e.message || ''}`, duration: 2 });
if (e instanceof Error) {
message.error({ content: `Error deleting link: \n ${e.message || ''}`, duration: 2 });
}
}
};

Expand Down

0 comments on commit 8dbbec4

Please sign in to comment.