MagicResponse class

The Magic Network Response wrapper.

This class wraps all HTTP responses, providing a consistent interface regardless of the underlying HTTP client. It mimics Laravel's Illuminate\Http\Client\Response.

Constructors

MagicResponse({required dynamic data, required int statusCode, Map<String, dynamic> headers = const {}, String? message})
Creates a new MagicResponse instance.

Properties

clientError bool
Check if the response was a client error (4xx).
no setter
data → dynamic
The raw response data.
final
errorMessage String?
Get the main error message.
no setter
errors Map<String, List<String>>
Get the validation errors map from a 422 response.
no setter
errorsList List<String>
Get all validation error messages as a flat list.
no setter
failed bool
Check if the response failed (4xx or 5xx status code).
no setter
firstError String?
Get the first validation error message.
no setter
forbidden bool
Check if the response was forbidden (403).
no setter
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, dynamic>
The response headers.
final
isValidationError bool
Check if the response is a validation error (422).
no setter
message String?
An optional message (useful for errors).
final
notFound bool
Check if the response was not found (404).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serverError bool
Check if the response was a server error (5xx).
no setter
statusCode int
The HTTP status code.
final
successful bool
Check if the response was successful (2xx status code).
no setter
unauthorized bool
Check if the response was unauthorized (401).
no setter

Methods

dataAs<T>() → T
Cast the data to a specific type.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String key) → dynamic
Get a value from the data map by key.