Skip to content

Instantly share code, notes, and snippets.

@kjivan
Last active February 7, 2024 17:17
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 kjivan/2e583320a1b4718ffccffd97cfe8bcf2 to your computer and use it in GitHub Desktop.
Save kjivan/2e583320a1b4718ffccffd97cfe8bcf2 to your computer and use it in GitHub Desktop.
Error Handling Best Practices

Error Handling Best Practices

  • System Errors
    • eg null pointers/failed db query/failed api calls
    • Log this at the error level
    • Log stack trace if possible
    • Log any relevant identifiers if possible
    • Don't log any unapproved sensitive data
  • User errors
    • eg invalid zip code/name length
    • Optionally log at warn level
      • Still an error for the user just not the system
    • Notify user of the error
      • Use Alerts, Toast, HTTP Codes/Payload, Kaka Message
        • Clearly define the specific issue
          • eg invalid last name is better than invalid request
          • eg last name too long is better than invalid last name
          • eg last name must be less than 25 characters better than last name too long
        • If it makes sense describe ways to correct issue
          • eg if database is locked ask user to retry later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment