NyResponse<T> class
Enhanced API Response class that provides access to the full Dio Response along with morphed data and useful response utilities
Constructors
- NyResponse({required Response? response, required T? data, required dynamic rawData})
- Constructor
- NyResponse.fromResponse({required Response response, required T? morphedData})
-
Factory constructor to create from Dio Response and morphed data
factory
Properties
- contentLength → String?
-
Get content length from headers
no setter
- contentType → String?
-
Get content type from headers
no setter
- data → T?
-
The morphed/decoded data of type T
final
- errorMessage → String?
-
Get an error message from the response.
no setter
-
extra
→ Map<
String, dynamic> ? -
Additional response information
no setter
- hasData → bool
-
Check if the response has data
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- headers → Headers?
-
Response headers
no setter
- isClientError → bool
-
Check if the response is a client error (status code 400-499)
no setter
- isConflict → bool
-
Check if there was a conflict (409)
no setter
- isForbidden → bool
-
Check if the response is forbidden (403)
no setter
- isNotFound → bool
-
Check if the resource was not found (404)
no setter
- isRateLimited → bool
-
Check if the request was rate limited (429)
no setter
- isRedirect → bool
-
Check if the response is a redirect (status code 300-399)
no setter
- isServerError → bool
-
Check if the response is a server error (status code 500-599)
no setter
- isSuccessful → bool
-
Check if the response was successful (status code 200-299)
no setter
- isTimeout → bool
-
Check if the request timed out (408)
no setter
-
Check if the response is unauthorized (401)
no setter
- rawData → dynamic
-
The raw response data
final
-
redirects
→ List<
RedirectRecord> ? -
Response redirect information
no setter
- requestOptions → RequestOptions?
-
Request options used for this request
no setter
- response → Response?
-
The original Dio Response object
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- statusCode → int?
-
HTTP status code
no setter
- statusMessage → String?
-
HTTP status message
no setter
Methods
-
dataOr(
T fallback) → T - Get the data or return a fallback value if data is null.
-
dataOrThrow(
[String? message]) → T - Get the data or throw an exception if data is null.
-
getHeader(
String name) → String? - Get a header value by name
-
getHeaderValues(
String name) → List< String> ? - Get all header values for a given name
-
ifSuccessful<
R> (R callback(T data)) → R? - Execute a callback if the response is successful, otherwise return null.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toMap(
) → Map< String, dynamic> - Convert response to a Map representation
-
toString(
) → String -
A string representation of this object.
override
-
when<
R> ({required R success(T data), required R failure(NyResponse< T> response)}) → R - Execute different callbacks based on success/failure.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited