Skip to main content

Overview

At Formbricks, we follow consistent error handling patterns to ensure reliability, debuggability, and maintainability across our codebase. This document outlines our standard approaches to error handling.

Core Principles

  1. Type Safety: Use typed errors and results
  2. Meaningful Messages: Provide clear, actionable error messages
  3. Proper Propagation: Handle or propagate errors appropriately
  4. Logging: Ensure errors are properly logged for debugging
  5. Recovery: Implement graceful fallbacks where possible

Standard Error Types

We maintain a set of standardized error types for different scenarios:

Error Handling Patterns

API Error Handling

For API endpoints:

Client-Side Error Handling

For client-side operations:

Best Practices

  1. Never Swallow Errors
    • Always handle or propagate errors
    • Log errors appropriately for debugging
    • Use error boundaries in React components
  2. Type Safety
    • Use typed error responses
    • Leverage TypeScript for compile-time error checking
    • Define clear error interfaces
  3. Error Messages
    • Include relevant context in error messages
    • Make messages actionable for developers
    • Use consistent error formatting
  4. Error Recovery
    • Implement fallback behaviors where appropriate
    • Gracefully degrade functionality when possible
    • Provide user feedback for recoverable errors
  5. Documentation
    • Document expected errors in function JSDoc
    • Include error handling in code examples
    • Keep error handling documentation up to date

Testing Error Scenarios

Always include error case testing:
These standards ensure consistent, reliable error handling across the Formbricks codebase while maintaining good developer experience and system reliability.