refactor: replace faultier with better-result for error handling #81
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Greptile Overview
Greptile Summary
This PR refactors the error handling system by replacing
faultierwithbetter-result, transitioning from Fault-based errors toTaggedErrorclasses.Key Changes
UnauthenticatedError,UnauthorizedError,SendEmailError, etc.) usingTaggedErrorfrom better-resultHTTPFault,TRPCFault) and serialization adaptersAreas Requiring Attention
apps/api/src/routes/index.ts:58) now only logserror.messageinstead of the previously captured structured metadata (cause, context, debug info, tags). This may reduce debugging capabilities for production issues.Confidence Score: 4/5
apps/api/src/routes/index.ts- verify that simplified error logging meets observability requirementsImportant Files Changed
TaggedErrorfrom better-result for authentication errorsAppErrortypeUnauthenticatedErrorandUnauthorizedErrorinstantiationFault.wrap()with direct error class instantiation for email send failuresSequence Diagram
sequenceDiagram participant Client participant API/Middleware participant Service participant ErrorClass as TaggedError (better-result) Note over Client,ErrorClass: Authentication Flow Client->>API/Middleware: Request (unauthenticated) API/Middleware->>API/Middleware: Validate session/identity API/Middleware->>ErrorClass: new UnauthenticatedError() ErrorClass-->>Client: Throw error Note over Client,ErrorClass: Authorization Flow Client->>API/Middleware: Request (non-admin user) API/Middleware->>API/Middleware: Check user role API/Middleware->>ErrorClass: new UnauthorizedError({userId}) ErrorClass-->>Client: Throw error with userId Note over Client,ErrorClass: Email Send Flow Client->>Service: sendEmail(body, params) Service->>Service: Resend API call Service->>Service: API returns error Service->>ErrorClass: new SendEmailError({emails, from, subject, text}) ErrorClass-->>Client: Throw error with metadata Note over Client,ErrorClass: Duration Parse Flow Client->>Service: parse(invalidString) Service->>Service: Validate input Service->>ErrorClass: new InvalidDurationParseInputError({value}) ErrorClass-->>Client: Throw error with value Note over API/Middleware,ErrorClass: Error Handling (apps/api) API/Middleware->>API/Middleware: onError handler catches error API/Middleware->>API/Middleware: Check if HTTPException alt is HTTPException API/Middleware-->>Client: Return exception response else other error API/Middleware->>API/Middleware: Log error.message API/Middleware->>API/Middleware: captureException(error) API/Middleware-->>Client: Return 500 Internal Server Error end