Failure.fromHttp constructor
Failure.fromHttp({})
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,
);
}