Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional chaining to reduce undefined errors #834

Merged
merged 1 commit into from
Mar 21, 2024
Merged

Conversation

daniellemaxwell
Copy link
Contributor

@daniellemaxwell daniellemaxwell commented Mar 21, 2024

Scope of changes

Adds optional chaining (?.) to check if a property is undefined. This should reduce the number of undefined errors logged to Sentry.

Fixes SC-24459

Type of change

  • new feature
  • bug fix
  • documentation
  • testing
  • technical debt
  • other (describe)

Definition of Done

  • I have manually tested the change running it locally (having rebuilt all containers) or via unit tests
  • I have added unit and/or integration tests that cover my changes
  • I have added new test fixtures as needed to support added tests
  • I have updated the dependencies list if necessary (including updating yarn.lock and/or go.sum)
  • I have recompiled and included new protocol buffers to reflect changes I made if necessary
  • Check this box if a reviewer can merge this pull request after approval (leave it unchecked if you want to do it yourself)
  • I have notified the reviewer via Shortcut or Slack that this is ready for review
  • Front-end: Checked sm, md, lg screen resolutions for effective responsiveness
  • Backend-end: Documented service configuration changes or created related devops stories

Reviewer(s) checklist

  • Front-end: I've reviewed the Figma design and confirmed that changes match the spec.
  • Any new user-facing content that has been added for this PR has been QA'ed to ensure correct grammar, spelling, and understandability.
  • Are there any TODOs in this PR that should be turned into stories?

Copy link

Copy link
Contributor

@pdeziel pdeziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change! Thanks for helping improve the usability of the sentry errors.

@@ -17,7 +17,7 @@ export function useFetchMember(memberID: string): MemberQuery {
...memberDetailQuery(memberID),
onError: (error: any) => {
// stop logging 401 & 403 errors to sentry
if (error.response.status !== 401 && error.response.status !== 403) {
if (error?.response?.status !== 401 && error?.response?.status !== 403) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am new to typescript and optional chaining - does this mean that if the error is undefined it will be not equal to both 401 and 403 and the exception will still be logged in the line below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional chaining, will check if the response object is null or undefined before attempting to read status. Currently, an error is thrown because the response hasn't been returned before attempting to read status.

@daniellemaxwell daniellemaxwell merged commit 8e5d66f into develop Mar 21, 2024
12 checks passed
@daniellemaxwell daniellemaxwell deleted the sc-24459 branch March 21, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants