Skip to content

Latest commit

 

History

History
56 lines (39 loc) · 1.34 KB

File metadata and controls

56 lines (39 loc) · 1.34 KB

Error Handling

Basic Policy

The application handles errors in two categories:

  1. Expected Errors
  2. Unexpected Errors

Expected Errors

Expected errors are handled using the option-t library's Result type in server functions, which return Result<T, Error>, and in actions by returning errors to the client using Conform's submission.reply(). These include:

  • Form validation errors
  • Entity constraints (e.g., uniqueness violations)
  • Not found errors

option-t example: add category function

conform example: add category action

Unexpected Errors

Unexpected errors are thrown and caught by ErrorBoundary. These include:

  • Database connection errors
  • Network errors
  • Runtime errors
  • Any other unhandled errors

Example:

export async function loader() {
  try {
    const data = await getData();
    return { data };
  } catch (error) {
    throw new Error("Unexpected error occurred", { cause: error });
  }
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
  
  return (
    <div>
      <h1>Error</h1>
      <p>An unexpected error occurred. Please try again later.</p>
    </div>
  );
}

Component Errors

React component errors are caught by the nearest ErrorBoundary