handle method

  1. @override
Future<ErrorResult> handle(
  1. Object error, [
  2. StackTrace? stackTrace
])
override

Handle an exception and return a standardized error result.

Implementation

@override
Future<ErrorResult> handle(
  Object error, [
  StackTrace? stackTrace,
]) async {
  // Build context for reporting
  final context = _buildRequestContext();

  // Report the exception
  if (error is AppException) {
    ExceptionReporter.reportAppException(error, stackTrace, context);
  } else {
    ExceptionReporter.reportException(error, stackTrace, context);
  }

  // Check for custom handler
  if (_handlers.containsKey(error.runtimeType)) {
    return _handlers[error.runtimeType]!(error, stackTrace);
  }

  // Default handling
  if (error is AppException) {
    return _mapAppException(error, stackTrace);
  } else {
    return _mapGenericException(error, stackTrace);
  }
}