Skip to content

Instantly share code, notes, and snippets.

@soorajshankar
Last active May 17, 2020 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soorajshankar/54c3552bec5542bfba33c8fb4c1a89cb to your computer and use it in GitHub Desktop.
Save soorajshankar/54c3552bec5542bfba33c8fb4c1a89cb to your computer and use it in GitHub Desktop.
coding best practices proposal

Error Handling

Avoid accessing values with multi level path

  1. Avoid accessing value from objects directly with more than 2 levels.
  2. Defaulting values will results in better error handling.
// Currently
<p>{data.schema.value}</p>
// if schema is undefined, entire UI will not show up.

// Proposed
<p>{data?.schema?.value | ''}</p>
// or 
<p>{data?.schema?.value | 'Invalid Data!'}</p>
// safely renders the UI, and if there is a data error user still be able to revert those changes if possible possible.
// lodash also has some better way to acces this, when there is a complex path.
  1. Now, even a small module has an error, entire application will not show up.
  2. Now, if such errors occured, user might have to clear the data from pg or to wait for the update.
  3. Better error message can be shown only at the place of error. all other modules remains functioning.

Cons

  1. We may have to handle analytics by writing extra code. error boundary will not trigger here at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment