Skip to content

Conversation

@naaa760
Copy link

@naaa760 naaa760 commented Nov 14, 2025

Summary

fix: #581

  • this PR refactors the entire server codebase to replace all try/catch blocks with neverthrow's Result and ResultAsync types for functional, type-safe error handling. This standardizes error handling across all layers (authentication, database, business logic, providers) and ensures all expected failure paths are explicitly typed.

  • The server previously mixed try/catch blocks and ad-hoc error handling across request, auth, and accounting layers, making control flow unpredictable and complicating typed error propagation. This refactoring:

  • Standardizes error handling on a single, type-safe pattern

  • Improves type safety by making all error paths explicit in function signatures

  • Enhances maintainability with consistent error handling patterns

  • Enables better error tracking with structured error types and context

Changes

New Error Infrastructure

  • src/errors/types.ts: Defines standardized BaseError interface and custom error classes
  • src/errors/result-helpers.ts: Utility functions for working with Result types
  • src/errors/index.ts: Central export for all error types and helpers

Refactored Services

  • Authentication layer now returns AppResultAsync
  • Core services (EchoControlService, DbService, ModelRequestService) use Results
  • Handlers check Result.isErr() instead of catching exceptions
  • Providers removed try/catch blocks (errors handled upstream)
  • Server error middleware handles BaseError, legacy HttpError, and generic Error types

Testing

  • TypeScript compilation passes
  • Build succeeds
  • All existing functionality preserved
  • Error handling paths verified

@vercel
Copy link
Contributor

vercel bot commented Nov 14, 2025

@naaa760 is attempting to deploy a commit to the Merit Systems Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Refactor] Remove all try/catch from the server replace with neverthow

1 participant