Failure.fromHttp constructor

Failure.fromHttp({
  1. String? message,
  2. int? status,
  3. String? url,
  4. String? method,
  5. Map<String, String>? headers,
  6. String? requestId,
  7. String? traceId,
  8. String? code,
  9. Map<String, dynamic>? body,
  10. bool? retryable,
})

Build from an HTTP failure (non-2xx) or thrown client exception.

Implementation

factory Failure.fromHttp({
  String? message,
  int? status,
  String? url,
  String? method,
  Map<String, String>? headers,
  String? requestId,
  String? traceId,
  String? code,
  Map<String, dynamic>? body, // if you parsed a JSON error body
  bool? retryable,
}) {
  final cat = _inferCategoryFromHttp(status);
  return Failure(
    errorMessage: message ?? 'An error occurred.',
    category: cat,
    code: code,
    status: status,
    url: url,
    method: method,
    headers: headers,
    requestId: requestId ?? body?['requestId']?.toString(),
    traceId: traceId ?? body?['traceId']?.toString(),
    retryable: retryable ?? _isRetryable(cat, status),
    retryAfter: _parseRetryAfter(headers, body),
    extensions: body,
  );
}