Failure constructor

const Failure({
  1. required String errorMessage,
  2. String? i18nKey,
  3. @Default.new(FailureCategory.unknown) FailureCategory category,
  4. String? code,
  5. String? operation,
  6. List<Map<String, dynamic>>? locations,
  7. List? path,
  8. Map<String, dynamic>? extensions,
  9. int? status,
  10. String? requestId,
  11. String? traceId,
  12. String? service,
  13. Map<String, List<String>>? validation,
  14. @Default.new(false) bool retryable,
  15. DateTime? retryAfter,
  16. String? url,
  17. String? method,
  18. Map<String, String>? headers,
  19. bool? tokenExpired,
  20. bool? canRefresh,
  21. String? debugMessage,
  22. String? stackTrace,
})

Implementation

const factory Failure({
  // --- Human / UI ---
  required String errorMessage, // e.g. GraphQL "message" or synthesized
  String? i18nKey, // optional localization key
  @Default(FailureCategory.unknown) FailureCategory category,

  // --- Programmatic code & operation context ---
  String? code, // e.g. extensions.code (Apollo), "UNAUTHENTICATED"
  String? operation, // GraphQL operation name, if known
  // --- GraphQL-specific (RFC-like shape) ---
  List<Map<String, dynamic>>? locations, // [{ line, column }]
  List<dynamic>? path, // ["mutation","createOrder",0,"id"]
  Map<String, dynamic>? extensions, // raw passthrough
  // Common extension picks (flattened for convenience)
  int? status, // extensions.http.status or gateway code
  String? requestId, // extensions.requestId / response header
  String? traceId, // extensions.traceId / tracing
  String? service, // downstream service identifier (if present)
  // Validation: field -> list of messages/codes
  Map<String, List<String>>? validation,

  // Retry hints / rate limit
  @Default(false) bool retryable,
  DateTime? retryAfter, // 429-style or custom backoff
  // Network/HTTP context (if available)
  String? url,
  String? method, // GET/POST...
  Map<String, String>? headers, // response/request headers minimal subset
  // Auth hints (optional, commonly present in extensions)
  bool? tokenExpired,
  bool? canRefresh,

  // Diagnostics (hide from end-user in prod UI)
  String? debugMessage,
  String? stackTrace,
}) = _Failure;