Error Handling Improvements - Implementation Plan
Status: In Progress Created: 2026-01-09 Last Updated: 2026-01-09
✅ Completed
Phase 1 - Infrastructure
Error Handling Infrastructure
Created
lib/errorIds.ts- Error ID constants for trackingCreated
lib/errorLogger.ts- Centralized error logging utilityFeatures: Environment-aware logging, Sentry-ready, user-friendly error messages
AuthService - sendMagicLink Fixed
Now checks if email actually sent before returning success
Returns proper error if email fails in production
Uses structured error logging with ERROR_IDS
Provides user-friendly error messages
Phase 2 - Critical Issues (5/5 complete)
AuthService - verifyMagicLink Fixed
Now throws specific error types instead of returning null
Errors include: EXPIRED_TOKEN, USER_LOOKUP_FAILED, USER_CREATE_FAILED, PROFILE_LOOKUP_FAILED, PROFILE_CREATE_FAILED
Each error includes errorId for tracking and user-friendly message
Database errors (code !== 'PGRST116') are distinguished from "not found"
Uses logError() with appropriate ERROR_IDS
AuthService - acceptInvite Fixed
Changed return type to
Promise<{ success: boolean; error?: string }>Now logs errors with ERROR_IDS.INVITE_NOT_FOUND, INVITE_EXPIRED, INVITE_ACCEPT_FAILED
Returns specific error messages for each failure case
verifyMagicLink now checks result and logs warning (non-blocking)
App.tsx - Seed Functions Fixed
Added
seedErrorstate and display bannerBoth seedShepherdRelationships and seedSupplierRelationships return
{ success: boolean; error?: string }Uses logError() with ERROR_IDS.RELATIONSHIP_SEED_FAILED
Shows dismissable warning banner (non-blocking, login still succeeds)
App.tsx - Signup Handlers Fixed
Added
signupErrorstateReplaced all
alert()calls with setSignupError()Updated MinimalSignup component to accept
errorandonClearErrorpropsDisplays inline error in form UI with red styling
Error clears when user starts typing (allows retry)
Uses logError() with ERROR_IDS.SIGNUP_FAILED, USER_CREATE_FAILED, PROFILE_CREATE_FAILED
App.tsx - handleSearch Fixed
Now provides specific error messages based on error type:
429: Rate limiting message
401/403: API configuration error
Network errors: Check internet connection
Timeout: Request timed out
5xx: Service temporarily unavailable
Uses logError() with ERROR_IDS.SEARCH_FAILED
Uses getUserFriendlyErrorMessage() for unknown errors
Phase 3 - High Priority Issues (6/6 complete)
SupplierTodoList.tsx Fixed
Added
loadErrorstate and error UI with retry buttonAdded
actionErrorstate for action handler failuresReplaced all
alert()calls with inline error messages on cardsAll action handlers (acknowledge, accept, decline, complete, unassign) now use logError()
Error IDs: REQUESTS_LOAD_FAILED, REQUEST_ACKNOWLEDGE_FAILED, REQUEST_ACCEPT_FAILED, REQUEST_DECLINE_FAILED, REQUEST_COMPLETE_FAILED, REQUEST_UNASSIGN_FAILED
RequestCard component now accepts errorMessage and onClearError props
PublicRequestFormHandler.tsx Fixed
Removed the
throwafter catching error (was causing uncaught rejection)Added
submitErrorandisSubmittingstateError displays as fixed banner at top (dismissable)
Uses logError() with ERROR_IDS.REQUEST_SUBMIT_FAILED
Allows retry without page refresh
NotificationService.ts - notifyOrganisation Fixed
Added try/catch for QueryService.getLastActiveCompanyUser() with logging
Added try/catch for company lookup with logging
Uses logError() with ERROR_IDS.ORG_ROUTING_FAILED, COMPANY_LOOKUP_FAILED
Added logWarning() for no routing target found
No longer fails silently on nested calls
RelationshipService.ts Fixed
loadFromStorage() now returns
{ success: boolean; warning?: string }Handles corrupted JSON with recovery (clears and warns user)
Handles invalid data format (not an array)
Skips corrupted individual entries with warning
saveToStorage() now returns
{ success: boolean; error?: string }Detects QuotaExceededError and provides specific message
All callers updated to check saveToStorage result
Error IDs: RELATIONSHIP_LOAD_FAILED, RELATIONSHIP_PARSE_FAILED, RELATIONSHIP_SAVE_FAILED, STORAGE_QUOTA_WARNING
AuthService.ts - Email Methods Fixed
sendDailyAccessEmail and sendMagicLinkEmail updated
In dev mode: returns true with console.log (allows testing without email config)
In prod with no config: logs error with EMAIL_CONFIG_MISSING and returns false
On API errors: logs error with EMAIL_API_ERROR including status code
Returns false on any failure with proper logging
Toast Notification System Created
Created
lib/toast.ts- Simple toast notification utilityPosition: fixed at bottom-right
Auto-dismiss: after 3 seconds (configurable)
Types: success, error, warning, info
Features: slide animations, click to dismiss, clear all
Usage:
toast.error('message'),toast.success('message')
Phase 4 - Final Issues (5/5 complete)
ManualRequestForm.tsx Fixed
Added
submitErrorstateReplaced alert with inline error banner (dismissable)
Uses logError() with ERROR_IDS.REQUEST_SUBMIT_FAILED
Error clears when user dismisses
FleetRequestForm.tsx Fixed
Added
submitErrorstateReplaced alert with inline error banner (dismissable)
Uses logError() with ERROR_IDS.REQUEST_SUBMIT_FAILED
Error displayed prominently below header
SupplierDirectory.tsx Fixed
Added
addSupplierErrorstateReplaced alert with inline error in add form
Uses logError() with ERROR_IDS.RELATIONSHIP_CREATE_FAILED
Error shows in context where it occurred
BaseChatInterface.tsx Fixed
Added
fileUploadErrorstateReplaced 3 alerts (file type, file size, upload failure) with inline error
File validation errors clear file input automatically
Uses logError() with ERROR_IDS.FILE_UPLOAD_FAILED
Error displays above input area with dismiss button
RequestSuccessPage.tsx Fixed
Replaced alert with toast.success() for clipboard copy
Uses toast notification system (lib/toast.ts)
Auto-dismisses after 3 seconds, user can click to dismiss
📊 Progress Tracking
Total Issues Identified: 18 Critical: 6 (Phase 1-2) High: 6 (Phase 3) Medium/Low: 6 (Phase 4)
Fixed: 18/18 (100%) ✅ In Progress: 0/18 (0%) Remaining: 0/18 (0%)
Phase 2 Summary (Completed 2026-01-09)
Fixed all 5 CRITICAL priority issues
AuthService now throws typed errors with errorIds
App.tsx uses inline error states instead of alerts
MinimalSignup component supports external error display
Search provides specific error guidance
Phase 3 Summary (Completed 2026-01-09)
Fixed all 6 HIGH priority issues
SupplierTodoList now shows load errors with retry button
SupplierTodoList action errors display inline on cards (no alerts)
PublicRequestFormHandler shows submit errors in fixed banner
NotificationService logs all failures in org routing
RelationshipService handles corrupted data gracefully
AuthService email methods properly log all failure modes
Created reusable Toast notification system
Phase 4 Summary (Completed 2026-01-09)
Fixed final 5 MEDIUM/LOW priority issues
ManualRequestForm shows submit errors inline (no alert)
FleetRequestForm shows submit errors inline (no alert)
SupplierDirectory shows add supplier errors inline (no alert)
BaseChatInterface shows file upload errors inline (no 3 alerts)
RequestSuccessPage uses toast for success notifications
ALL 18 ISSUES NOW FIXED (100% COMPLETE)
🎯 Next Steps
✅ All 18 error handling issues have been fixed!
Recommended follow-ups:
Test error paths intentionally in dev/staging
Consider adding Sentry integration for production error tracking
Monitor error rates after deployment using ERROR_IDS
Document error codes for support team reference
Optional: Add more toast notifications for success actions
📝 Usage Examples
Error Logging
Toast Notifications
📝 Notes
All fixes use
logError()fromlib/errorLogger.tsAll error IDs come from
lib/errorIds.tsIn dev: verbose logging, in prod: user-friendly messages
Always provide retry mechanisms for recoverable errors
Never silently continue after critical failures
Last updated
Was this helpful?