diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2254628..a52bfc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,9 @@ on: pull_request: branches: [ main ] +env: + DART_VERSION: 3.5.0 + jobs: ci: runs-on: ubuntu-latest @@ -22,7 +25,7 @@ jobs: - name: Setup dart uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f # v1.5.0 with: - sdk: 3.3.1 + sdk: ${{ env.DART_VERSION }} - name: Install dependencies run: dart pub get @@ -49,7 +52,7 @@ jobs: - name: Setup dart uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f # v1.5.0 with: - sdk: 3.3.1 + sdk: ${{ env.DART_VERSION }} - name: Install dependencies run: | diff --git a/example/main.dart b/example/main.dart index 642b80c..b1b55db 100644 --- a/example/main.dart +++ b/example/main.dart @@ -1,7 +1,5 @@ import 'package:charlatan/charlatan.dart'; -import 'package:sturdy_http/src/network_request.dart'; -import 'package:sturdy_http/src/sturdy_http.dart'; -import 'package:sturdy_http/src/sturdy_http_event_listener.dart'; +import 'package:sturdy_http/sturdy_http.dart'; void main(List args) async { // Set up some fake HTTP responses using Charlatan @@ -25,13 +23,13 @@ void main(List args) async { ); // A GetRequest. Prints 'Hello World!'. - await client.execute( + await client.execute( GetRequest('/foo'), onResponse: (r) { - r.maybeWhen( - ok: (message) => print(message), - orElse: () => print('GET /foo failed: $r'), - ); + return switch (r) { + OkResponse(:final response) => print(response), + _ => print('GET /foo failed: $r'), + }; }, ); @@ -40,13 +38,13 @@ void main(List args) async { // Prints: // 'mutative request success' <-- From ExampleEventListener // 'success!' - await client.execute( + await client.execute( PostRequest('/foo', data: NetworkRequestBody.empty()), onResponse: (r) { - r.maybeWhen( - okNoContent: () => print('success!'), - orElse: () => print('POST /foo failed: $r'), - ); + return switch (r) { + OkNoContent() => print('success!'), + _ => print('POST /foo failed: $r'), + }; }, ); } diff --git a/lib/src/network_response.dart b/lib/src/network_response.dart index 3ea7645..0479c2a 100644 --- a/lib/src/network_response.dart +++ b/lib/src/network_response.dart @@ -1,8 +1,6 @@ -import 'package:dio/dio.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:sturdy_http/sturdy_http.dart'; +// ignore_for_file: public_member_api_docs -part 'network_response.freezed.dart'; +import 'package:dio/dio.dart'; /// The produced object after [SturdyHttp] processes a [NetworkRequest]. /// @@ -12,58 +10,99 @@ part 'network_response.freezed.dart'; /// Most often the call sites executing a [NetworkRequest] will only be interested /// in a select few of these, and will resolve their error cases via a `maybeWhen` /// using the `orElse` clause. -@freezed -class NetworkResponse with _$NetworkResponse { - /// 200 - for successful responses that include a body. - const factory NetworkResponse.ok(R response) = _Ok; - - /// 204 - for successful responses that don't include a body. - const factory NetworkResponse.okNoContent() = _OkNoContent; - - /// 401 - for responses when the request was missing required authentication. - const factory NetworkResponse.unauthorized(DioException error) = - _Unauthorized; - - /// 403 - for responses when the request was authenticated but the - /// action is not authorized/allowed. - const factory NetworkResponse.forbidden(DioException error) = _Forbidden; - - /// 404 - for responses when we could not locate a resource, or when - /// someone would attempt to access a forbidden resource due to a bug. - const factory NetworkResponse.notFound(DioException error) = _NotFound; - - /// 422 - for responses when the request inputs failed our validations. - const factory NetworkResponse.unprocessableEntity({ - required DioException error, - required R response, - }) = _UnprocessableEntity; - - /// 426 - for responses when access to a resource requires a client upgrade. - const factory NetworkResponse.upgradeRequired(DioException error) = - _UpgradeRequired; - - /// 500 - for responses where the service had an error while processing - /// the request. - const factory NetworkResponse.serverError(DioException error) = _ServerError; - - /// 503 - for responses when an underlying service issue prevents us from - /// fulfilling the request. - const factory NetworkResponse.serviceUnavailable(DioException error) = - _ServiceUnavailable; - - /// An error designated as a fallback in the event that we receive a status code - /// we don't explicitly handle *or* a request or response otherwise fails to meet - /// our expectations as "valid". The [message] will describe the condition and a - /// [DioException] will be present if it was available as a result of the request. - const factory NetworkResponse.genericError({ - required String message, - required bool isConnectionIssue, - DioException? error, - }) = _GenericError; +sealed class NetworkResponse { + const NetworkResponse(); +} + +sealed class NetworkResponseSuccess extends NetworkResponse { + const NetworkResponseSuccess(); +} + +final class OkNoContent extends NetworkResponseSuccess { + const OkNoContent(); +} + +final class OkResponse extends NetworkResponseSuccess { + final T response; + + const OkResponse(this.response); +} + +sealed class NetworkResponseFailure extends NetworkResponse { + const NetworkResponseFailure(); +} + +/// 401 - for responses when the request was missing required authentication. +final class Unauthorized extends NetworkResponseFailure { + final DioException error; + + const Unauthorized({required this.error}); +} + +/// 403 - for responses when the request was authenticated but the +/// action is not authorized/allowed. +final class Forbidden extends NetworkResponseFailure { + final DioException error; + + const Forbidden({required this.error}); +} + +/// 404 - for responses when we could not locate a resource, or when +/// someone would attempt to access a forbidden resource due to a bug. +final class NotFound extends NetworkResponseFailure { + final DioException error; + + const NotFound({required this.error}); +} + +/// 422 - for responses when the request inputs failed our validations. +final class UnprocessableEntity extends NetworkResponseFailure { + final DioException error; + final R response; + + const UnprocessableEntity({required this.error, required this.response}); +} + +/// 426 - for responses when a client version upgrade is required +final class UpgradeRequired extends NetworkResponseFailure { + final DioException error; + + const UpgradeRequired({required this.error}); +} + +/// 500 - for responses where the service had an error while processing +/// the request. +final class ServerError extends NetworkResponseFailure { + final DioException error; + + const ServerError({required this.error}); +} + +/// 503 - for responses when an underlying service issue prevents us from +/// fulfilling the request. +final class ServiceUnavailable extends NetworkResponseFailure { + final DioException error; + + const ServiceUnavailable({required this.error}); +} + +/// Any "other" error not covered by the above cases. If a [DioException] is present, +/// it has an error status we don't handle. Often this error will occur when no +/// response was received from the server. +final class GenericError extends NetworkResponseFailure { + const GenericError({ + this.error, + required this.message, + required this.isConnectionIssue, + }); + + final DioException? error; + final String message; + final bool isConnectionIssue; } /// Extensions on the [NetworkResponse] type -extension NetworkResponseX on NetworkResponse { +extension NetworkResponseX on NetworkResponse { /// Whether this [NetworkResponse] should be considered successful - bool get isSuccess => this is _Ok || this is _OkNoContent; + bool get isSuccess => this is NetworkResponseSuccess; } diff --git a/lib/src/network_response.freezed.dart b/lib/src/network_response.freezed.dart deleted file mode 100644 index 45a7989..0000000 --- a/lib/src/network_response.freezed.dart +++ /dev/null @@ -1,2035 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'network_response.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$NetworkResponse { - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $NetworkResponseCopyWith { - factory $NetworkResponseCopyWith( - NetworkResponse value, $Res Function(NetworkResponse) then) = - _$NetworkResponseCopyWithImpl>; -} - -/// @nodoc -class _$NetworkResponseCopyWithImpl> - implements $NetworkResponseCopyWith { - _$NetworkResponseCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; -} - -/// @nodoc -abstract class _$$OkImplCopyWith { - factory _$$OkImplCopyWith( - _$OkImpl value, $Res Function(_$OkImpl) then) = - __$$OkImplCopyWithImpl; - @useResult - $Res call({R response}); -} - -/// @nodoc -class __$$OkImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$OkImplCopyWith { - __$$OkImplCopyWithImpl(_$OkImpl _value, $Res Function(_$OkImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? response = freezed, - }) { - return _then(_$OkImpl( - freezed == response - ? _value.response - : response // ignore: cast_nullable_to_non_nullable - as R, - )); - } -} - -/// @nodoc - -class _$OkImpl implements _Ok { - const _$OkImpl(this.response); - - @override - final R response; - - @override - String toString() { - return 'NetworkResponse<$R>.ok(response: $response)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$OkImpl && - const DeepCollectionEquality().equals(other.response, response)); - } - - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(response)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$OkImplCopyWith> get copyWith => - __$$OkImplCopyWithImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return ok(response); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return ok?.call(response); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (ok != null) { - return ok(response); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return ok(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return ok?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (ok != null) { - return ok(this); - } - return orElse(); - } -} - -abstract class _Ok implements NetworkResponse { - const factory _Ok(final R response) = _$OkImpl; - - R get response; - @JsonKey(ignore: true) - _$$OkImplCopyWith> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$OkNoContentImplCopyWith { - factory _$$OkNoContentImplCopyWith(_$OkNoContentImpl value, - $Res Function(_$OkNoContentImpl) then) = - __$$OkNoContentImplCopyWithImpl; -} - -/// @nodoc -class __$$OkNoContentImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$OkNoContentImplCopyWith { - __$$OkNoContentImplCopyWithImpl( - _$OkNoContentImpl _value, $Res Function(_$OkNoContentImpl) _then) - : super(_value, _then); -} - -/// @nodoc - -class _$OkNoContentImpl implements _OkNoContent { - const _$OkNoContentImpl(); - - @override - String toString() { - return 'NetworkResponse<$R>.okNoContent()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$OkNoContentImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return okNoContent(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return okNoContent?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (okNoContent != null) { - return okNoContent(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return okNoContent(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return okNoContent?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (okNoContent != null) { - return okNoContent(this); - } - return orElse(); - } -} - -abstract class _OkNoContent implements NetworkResponse { - const factory _OkNoContent() = _$OkNoContentImpl; -} - -/// @nodoc -abstract class _$$UnauthorizedImplCopyWith { - factory _$$UnauthorizedImplCopyWith(_$UnauthorizedImpl value, - $Res Function(_$UnauthorizedImpl) then) = - __$$UnauthorizedImplCopyWithImpl; - @useResult - $Res call({DioException error}); -} - -/// @nodoc -class __$$UnauthorizedImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$UnauthorizedImplCopyWith { - __$$UnauthorizedImplCopyWithImpl( - _$UnauthorizedImpl _value, $Res Function(_$UnauthorizedImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? error = null, - }) { - return _then(_$UnauthorizedImpl( - null == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException, - )); - } -} - -/// @nodoc - -class _$UnauthorizedImpl implements _Unauthorized { - const _$UnauthorizedImpl(this.error); - - @override - final DioException error; - - @override - String toString() { - return 'NetworkResponse<$R>.unauthorized(error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$UnauthorizedImpl && - (identical(other.error, error) || other.error == error)); - } - - @override - int get hashCode => Object.hash(runtimeType, error); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$UnauthorizedImplCopyWith> get copyWith => - __$$UnauthorizedImplCopyWithImpl>( - this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return unauthorized(error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return unauthorized?.call(error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (unauthorized != null) { - return unauthorized(error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return unauthorized(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return unauthorized?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (unauthorized != null) { - return unauthorized(this); - } - return orElse(); - } -} - -abstract class _Unauthorized implements NetworkResponse { - const factory _Unauthorized(final DioException error) = _$UnauthorizedImpl; - - DioException get error; - @JsonKey(ignore: true) - _$$UnauthorizedImplCopyWith> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$ForbiddenImplCopyWith { - factory _$$ForbiddenImplCopyWith( - _$ForbiddenImpl value, $Res Function(_$ForbiddenImpl) then) = - __$$ForbiddenImplCopyWithImpl; - @useResult - $Res call({DioException error}); -} - -/// @nodoc -class __$$ForbiddenImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$ForbiddenImplCopyWith { - __$$ForbiddenImplCopyWithImpl( - _$ForbiddenImpl _value, $Res Function(_$ForbiddenImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? error = null, - }) { - return _then(_$ForbiddenImpl( - null == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException, - )); - } -} - -/// @nodoc - -class _$ForbiddenImpl implements _Forbidden { - const _$ForbiddenImpl(this.error); - - @override - final DioException error; - - @override - String toString() { - return 'NetworkResponse<$R>.forbidden(error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ForbiddenImpl && - (identical(other.error, error) || other.error == error)); - } - - @override - int get hashCode => Object.hash(runtimeType, error); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$ForbiddenImplCopyWith> get copyWith => - __$$ForbiddenImplCopyWithImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return forbidden(error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return forbidden?.call(error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (forbidden != null) { - return forbidden(error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return forbidden(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return forbidden?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (forbidden != null) { - return forbidden(this); - } - return orElse(); - } -} - -abstract class _Forbidden implements NetworkResponse { - const factory _Forbidden(final DioException error) = _$ForbiddenImpl; - - DioException get error; - @JsonKey(ignore: true) - _$$ForbiddenImplCopyWith> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$NotFoundImplCopyWith { - factory _$$NotFoundImplCopyWith( - _$NotFoundImpl value, $Res Function(_$NotFoundImpl) then) = - __$$NotFoundImplCopyWithImpl; - @useResult - $Res call({DioException error}); -} - -/// @nodoc -class __$$NotFoundImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$NotFoundImplCopyWith { - __$$NotFoundImplCopyWithImpl( - _$NotFoundImpl _value, $Res Function(_$NotFoundImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? error = null, - }) { - return _then(_$NotFoundImpl( - null == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException, - )); - } -} - -/// @nodoc - -class _$NotFoundImpl implements _NotFound { - const _$NotFoundImpl(this.error); - - @override - final DioException error; - - @override - String toString() { - return 'NetworkResponse<$R>.notFound(error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$NotFoundImpl && - (identical(other.error, error) || other.error == error)); - } - - @override - int get hashCode => Object.hash(runtimeType, error); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$NotFoundImplCopyWith> get copyWith => - __$$NotFoundImplCopyWithImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return notFound(error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return notFound?.call(error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (notFound != null) { - return notFound(error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return notFound(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return notFound?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (notFound != null) { - return notFound(this); - } - return orElse(); - } -} - -abstract class _NotFound implements NetworkResponse { - const factory _NotFound(final DioException error) = _$NotFoundImpl; - - DioException get error; - @JsonKey(ignore: true) - _$$NotFoundImplCopyWith> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$UnprocessableEntityImplCopyWith { - factory _$$UnprocessableEntityImplCopyWith(_$UnprocessableEntityImpl value, - $Res Function(_$UnprocessableEntityImpl) then) = - __$$UnprocessableEntityImplCopyWithImpl; - @useResult - $Res call({DioException error, R response}); -} - -/// @nodoc -class __$$UnprocessableEntityImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$UnprocessableEntityImplCopyWith { - __$$UnprocessableEntityImplCopyWithImpl(_$UnprocessableEntityImpl _value, - $Res Function(_$UnprocessableEntityImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? error = null, - Object? response = freezed, - }) { - return _then(_$UnprocessableEntityImpl( - error: null == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException, - response: freezed == response - ? _value.response - : response // ignore: cast_nullable_to_non_nullable - as R, - )); - } -} - -/// @nodoc - -class _$UnprocessableEntityImpl implements _UnprocessableEntity { - const _$UnprocessableEntityImpl( - {required this.error, required this.response}); - - @override - final DioException error; - @override - final R response; - - @override - String toString() { - return 'NetworkResponse<$R>.unprocessableEntity(error: $error, response: $response)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$UnprocessableEntityImpl && - (identical(other.error, error) || other.error == error) && - const DeepCollectionEquality().equals(other.response, response)); - } - - @override - int get hashCode => Object.hash( - runtimeType, error, const DeepCollectionEquality().hash(response)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$UnprocessableEntityImplCopyWith> - get copyWith => __$$UnprocessableEntityImplCopyWithImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return unprocessableEntity(error, response); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return unprocessableEntity?.call(error, response); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (unprocessableEntity != null) { - return unprocessableEntity(error, response); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return unprocessableEntity(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return unprocessableEntity?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (unprocessableEntity != null) { - return unprocessableEntity(this); - } - return orElse(); - } -} - -abstract class _UnprocessableEntity implements NetworkResponse { - const factory _UnprocessableEntity( - {required final DioException error, - required final R response}) = _$UnprocessableEntityImpl; - - DioException get error; - R get response; - @JsonKey(ignore: true) - _$$UnprocessableEntityImplCopyWith> - get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$UpgradeRequiredImplCopyWith { - factory _$$UpgradeRequiredImplCopyWith(_$UpgradeRequiredImpl value, - $Res Function(_$UpgradeRequiredImpl) then) = - __$$UpgradeRequiredImplCopyWithImpl; - @useResult - $Res call({DioException error}); -} - -/// @nodoc -class __$$UpgradeRequiredImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$UpgradeRequiredImplCopyWith { - __$$UpgradeRequiredImplCopyWithImpl(_$UpgradeRequiredImpl _value, - $Res Function(_$UpgradeRequiredImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? error = null, - }) { - return _then(_$UpgradeRequiredImpl( - null == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException, - )); - } -} - -/// @nodoc - -class _$UpgradeRequiredImpl implements _UpgradeRequired { - const _$UpgradeRequiredImpl(this.error); - - @override - final DioException error; - - @override - String toString() { - return 'NetworkResponse<$R>.upgradeRequired(error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$UpgradeRequiredImpl && - (identical(other.error, error) || other.error == error)); - } - - @override - int get hashCode => Object.hash(runtimeType, error); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$UpgradeRequiredImplCopyWith> get copyWith => - __$$UpgradeRequiredImplCopyWithImpl>( - this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return upgradeRequired(error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return upgradeRequired?.call(error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (upgradeRequired != null) { - return upgradeRequired(error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return upgradeRequired(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return upgradeRequired?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (upgradeRequired != null) { - return upgradeRequired(this); - } - return orElse(); - } -} - -abstract class _UpgradeRequired implements NetworkResponse { - const factory _UpgradeRequired(final DioException error) = - _$UpgradeRequiredImpl; - - DioException get error; - @JsonKey(ignore: true) - _$$UpgradeRequiredImplCopyWith> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$ServerErrorImplCopyWith { - factory _$$ServerErrorImplCopyWith(_$ServerErrorImpl value, - $Res Function(_$ServerErrorImpl) then) = - __$$ServerErrorImplCopyWithImpl; - @useResult - $Res call({DioException error}); -} - -/// @nodoc -class __$$ServerErrorImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$ServerErrorImplCopyWith { - __$$ServerErrorImplCopyWithImpl( - _$ServerErrorImpl _value, $Res Function(_$ServerErrorImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? error = null, - }) { - return _then(_$ServerErrorImpl( - null == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException, - )); - } -} - -/// @nodoc - -class _$ServerErrorImpl implements _ServerError { - const _$ServerErrorImpl(this.error); - - @override - final DioException error; - - @override - String toString() { - return 'NetworkResponse<$R>.serverError(error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ServerErrorImpl && - (identical(other.error, error) || other.error == error)); - } - - @override - int get hashCode => Object.hash(runtimeType, error); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$ServerErrorImplCopyWith> get copyWith => - __$$ServerErrorImplCopyWithImpl>( - this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return serverError(error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return serverError?.call(error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (serverError != null) { - return serverError(error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return serverError(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return serverError?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (serverError != null) { - return serverError(this); - } - return orElse(); - } -} - -abstract class _ServerError implements NetworkResponse { - const factory _ServerError(final DioException error) = _$ServerErrorImpl; - - DioException get error; - @JsonKey(ignore: true) - _$$ServerErrorImplCopyWith> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$ServiceUnavailableImplCopyWith { - factory _$$ServiceUnavailableImplCopyWith(_$ServiceUnavailableImpl value, - $Res Function(_$ServiceUnavailableImpl) then) = - __$$ServiceUnavailableImplCopyWithImpl; - @useResult - $Res call({DioException error}); -} - -/// @nodoc -class __$$ServiceUnavailableImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$ServiceUnavailableImplCopyWith { - __$$ServiceUnavailableImplCopyWithImpl(_$ServiceUnavailableImpl _value, - $Res Function(_$ServiceUnavailableImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? error = null, - }) { - return _then(_$ServiceUnavailableImpl( - null == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException, - )); - } -} - -/// @nodoc - -class _$ServiceUnavailableImpl implements _ServiceUnavailable { - const _$ServiceUnavailableImpl(this.error); - - @override - final DioException error; - - @override - String toString() { - return 'NetworkResponse<$R>.serviceUnavailable(error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ServiceUnavailableImpl && - (identical(other.error, error) || other.error == error)); - } - - @override - int get hashCode => Object.hash(runtimeType, error); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$ServiceUnavailableImplCopyWith> - get copyWith => __$$ServiceUnavailableImplCopyWithImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return serviceUnavailable(error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return serviceUnavailable?.call(error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (serviceUnavailable != null) { - return serviceUnavailable(error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return serviceUnavailable(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return serviceUnavailable?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (serviceUnavailable != null) { - return serviceUnavailable(this); - } - return orElse(); - } -} - -abstract class _ServiceUnavailable implements NetworkResponse { - const factory _ServiceUnavailable(final DioException error) = - _$ServiceUnavailableImpl; - - DioException get error; - @JsonKey(ignore: true) - _$$ServiceUnavailableImplCopyWith> - get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$GenericErrorImplCopyWith { - factory _$$GenericErrorImplCopyWith(_$GenericErrorImpl value, - $Res Function(_$GenericErrorImpl) then) = - __$$GenericErrorImplCopyWithImpl; - @useResult - $Res call({String message, bool isConnectionIssue, DioException? error}); -} - -/// @nodoc -class __$$GenericErrorImplCopyWithImpl - extends _$NetworkResponseCopyWithImpl> - implements _$$GenericErrorImplCopyWith { - __$$GenericErrorImplCopyWithImpl( - _$GenericErrorImpl _value, $Res Function(_$GenericErrorImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? message = null, - Object? isConnectionIssue = null, - Object? error = freezed, - }) { - return _then(_$GenericErrorImpl( - message: null == message - ? _value.message - : message // ignore: cast_nullable_to_non_nullable - as String, - isConnectionIssue: null == isConnectionIssue - ? _value.isConnectionIssue - : isConnectionIssue // ignore: cast_nullable_to_non_nullable - as bool, - error: freezed == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as DioException?, - )); - } -} - -/// @nodoc - -class _$GenericErrorImpl implements _GenericError { - const _$GenericErrorImpl( - {required this.message, required this.isConnectionIssue, this.error}); - - @override - final String message; - @override - final bool isConnectionIssue; - @override - final DioException? error; - - @override - String toString() { - return 'NetworkResponse<$R>.genericError(message: $message, isConnectionIssue: $isConnectionIssue, error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$GenericErrorImpl && - (identical(other.message, message) || other.message == message) && - (identical(other.isConnectionIssue, isConnectionIssue) || - other.isConnectionIssue == isConnectionIssue) && - (identical(other.error, error) || other.error == error)); - } - - @override - int get hashCode => - Object.hash(runtimeType, message, isConnectionIssue, error); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$GenericErrorImplCopyWith> get copyWith => - __$$GenericErrorImplCopyWithImpl>( - this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(R response) ok, - required TResult Function() okNoContent, - required TResult Function(DioException error) unauthorized, - required TResult Function(DioException error) forbidden, - required TResult Function(DioException error) notFound, - required TResult Function(DioException error, R response) - unprocessableEntity, - required TResult Function(DioException error) upgradeRequired, - required TResult Function(DioException error) serverError, - required TResult Function(DioException error) serviceUnavailable, - required TResult Function( - String message, bool isConnectionIssue, DioException? error) - genericError, - }) { - return genericError(message, isConnectionIssue, error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(R response)? ok, - TResult? Function()? okNoContent, - TResult? Function(DioException error)? unauthorized, - TResult? Function(DioException error)? forbidden, - TResult? Function(DioException error)? notFound, - TResult? Function(DioException error, R response)? unprocessableEntity, - TResult? Function(DioException error)? upgradeRequired, - TResult? Function(DioException error)? serverError, - TResult? Function(DioException error)? serviceUnavailable, - TResult? Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - }) { - return genericError?.call(message, isConnectionIssue, error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(R response)? ok, - TResult Function()? okNoContent, - TResult Function(DioException error)? unauthorized, - TResult Function(DioException error)? forbidden, - TResult Function(DioException error)? notFound, - TResult Function(DioException error, R response)? unprocessableEntity, - TResult Function(DioException error)? upgradeRequired, - TResult Function(DioException error)? serverError, - TResult Function(DioException error)? serviceUnavailable, - TResult Function( - String message, bool isConnectionIssue, DioException? error)? - genericError, - required TResult orElse(), - }) { - if (genericError != null) { - return genericError(message, isConnectionIssue, error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Ok value) ok, - required TResult Function(_OkNoContent value) okNoContent, - required TResult Function(_Unauthorized value) unauthorized, - required TResult Function(_Forbidden value) forbidden, - required TResult Function(_NotFound value) notFound, - required TResult Function(_UnprocessableEntity value) - unprocessableEntity, - required TResult Function(_UpgradeRequired value) upgradeRequired, - required TResult Function(_ServerError value) serverError, - required TResult Function(_ServiceUnavailable value) serviceUnavailable, - required TResult Function(_GenericError value) genericError, - }) { - return genericError(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Ok value)? ok, - TResult? Function(_OkNoContent value)? okNoContent, - TResult? Function(_Unauthorized value)? unauthorized, - TResult? Function(_Forbidden value)? forbidden, - TResult? Function(_NotFound value)? notFound, - TResult? Function(_UnprocessableEntity value)? unprocessableEntity, - TResult? Function(_UpgradeRequired value)? upgradeRequired, - TResult? Function(_ServerError value)? serverError, - TResult? Function(_ServiceUnavailable value)? serviceUnavailable, - TResult? Function(_GenericError value)? genericError, - }) { - return genericError?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Ok value)? ok, - TResult Function(_OkNoContent value)? okNoContent, - TResult Function(_Unauthorized value)? unauthorized, - TResult Function(_Forbidden value)? forbidden, - TResult Function(_NotFound value)? notFound, - TResult Function(_UnprocessableEntity value)? unprocessableEntity, - TResult Function(_UpgradeRequired value)? upgradeRequired, - TResult Function(_ServerError value)? serverError, - TResult Function(_ServiceUnavailable value)? serviceUnavailable, - TResult Function(_GenericError value)? genericError, - required TResult orElse(), - }) { - if (genericError != null) { - return genericError(this); - } - return orElse(); - } -} - -abstract class _GenericError implements NetworkResponse { - const factory _GenericError( - {required final String message, - required final bool isConnectionIssue, - final DioException? error}) = _$GenericErrorImpl; - - String get message; - bool get isConnectionIssue; - DioException? get error; - @JsonKey(ignore: true) - _$$GenericErrorImplCopyWith> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/src/sturdy_http.dart b/lib/src/sturdy_http.dart index 7f48491..0c62f7e 100644 --- a/lib/src/sturdy_http.dart +++ b/lib/src/sturdy_http.dart @@ -154,7 +154,7 @@ class SturdyHttp { onSendProgress: request.onSendProgress, ); if (dioResponse.statusCode == 204) { - resolvedResponse = const NetworkResponse.okNoContent(); + resolvedResponse = const OkNoContent(); } else { final data = dioResponse.data; if (data == null || data is! R) { @@ -168,43 +168,43 @@ class SturdyHttp { return 'Request to ${request.path} was successful but response data $messageSuffix'; } - resolvedResponse = NetworkResponse.genericError( + resolvedResponse = GenericError( message: buildErrorMessage(), isConnectionIssue: false, ); } else { - resolvedResponse = NetworkResponse.ok(data as R); + resolvedResponse = OkResponse(data as R); } } } on DioException catch (error) { switch (error.response?.statusCode) { case 401: await _onEvent(SturdyHttpEvent.authFailure(error.requestOptions)); - resolvedResponse = NetworkResponse.unauthorized(error); + resolvedResponse = Unauthorized(error: error); break; case 403: - resolvedResponse = NetworkResponse.forbidden(error); + resolvedResponse = Forbidden(error: error); break; case 404: - resolvedResponse = NetworkResponse.notFound(error); + resolvedResponse = NotFound(error: error); break; case 422: - resolvedResponse = NetworkResponse.unprocessableEntity( + resolvedResponse = UnprocessableEntity( error: error, response: error.response?.data as R, ); break; case 426: - resolvedResponse = NetworkResponse.upgradeRequired(error); + resolvedResponse = UpgradeRequired(error: error); break; case 500: - resolvedResponse = NetworkResponse.serverError(error); + resolvedResponse = ServerError(error: error); break; case 503: - resolvedResponse = NetworkResponse.serviceUnavailable(error); + resolvedResponse = ServiceUnavailable(error: error); break; default: - resolvedResponse = NetworkResponse.genericError( + resolvedResponse = GenericError( message: 'Unexpected status code ${error.response?.statusCode} returned for ${request.path}', isConnectionIssue: error.isConnectionIssue(), @@ -241,7 +241,7 @@ class SturdyHttp { ); } - return _ResponsePayload( + return _ResponsePayload( request: request, dioResponse: response.$1, resolvedResponse: response.$2, @@ -249,10 +249,10 @@ class SturdyHttp { } } -class _ResponsePayload { +class _ResponsePayload { final NetworkRequest request; final Response? dioResponse; - final NetworkResponse resolvedResponse; + final NetworkResponse resolvedResponse; _ResponsePayload({ required this.request, diff --git a/lib/src/sturdy_http_event_listener.dart b/lib/src/sturdy_http_event_listener.dart index 735199f..2e996b7 100644 --- a/lib/src/sturdy_http_event_listener.dart +++ b/lib/src/sturdy_http_event_listener.dart @@ -1,6 +1,5 @@ import 'package:dio/dio.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:sturdy_http/sturdy_http.dart'; part 'sturdy_http_event_listener.freezed.dart'; diff --git a/lib/src/sturdy_http_event_listener.freezed.dart b/lib/src/sturdy_http_event_listener.freezed.dart index 9a12143..dab4ba9 100644 --- a/lib/src/sturdy_http_event_listener.freezed.dart +++ b/lib/src/sturdy_http_event_listener.freezed.dart @@ -69,7 +69,9 @@ mixin _$SturdyHttpEvent { }) => throw _privateConstructorUsedError; - @JsonKey(ignore: true) + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) $SturdyHttpEventCopyWith get copyWith => throw _privateConstructorUsedError; } @@ -93,6 +95,8 @@ class _$SturdyHttpEventCopyWithImpl<$Res, $Val extends SturdyHttpEvent> // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -127,6 +131,8 @@ class __$$JsonDecodingErrorImplCopyWithImpl<$Res> $Res Function(_$JsonDecodingErrorImpl) _then) : super(_value, _then); + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -183,7 +189,9 @@ class _$JsonDecodingErrorImpl implements _JsonDecodingError { @override int get hashCode => Object.hash(runtimeType, request, exception, stackTrace); - @JsonKey(ignore: true) + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$JsonDecodingErrorImplCopyWith<_$JsonDecodingErrorImpl> get copyWith => @@ -276,8 +284,11 @@ abstract class _JsonDecodingError implements SturdyHttpEvent { RequestOptions get request; Exception get exception; StackTrace? get stackTrace; + + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) _$$JsonDecodingErrorImplCopyWith<_$JsonDecodingErrorImpl> get copyWith => throw _privateConstructorUsedError; } @@ -301,6 +312,8 @@ class __$$AuthFailureImplCopyWithImpl<$Res> _$AuthFailureImpl _value, $Res Function(_$AuthFailureImpl) _then) : super(_value, _then); + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -339,7 +352,9 @@ class _$AuthFailureImpl implements _AuthFailure { @override int get hashCode => Object.hash(runtimeType, request); - @JsonKey(ignore: true) + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$AuthFailureImplCopyWith<_$AuthFailureImpl> get copyWith => @@ -426,8 +441,11 @@ abstract class _AuthFailure implements SturdyHttpEvent { @override RequestOptions get request; + + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) _$$AuthFailureImplCopyWith<_$AuthFailureImpl> get copyWith => throw _privateConstructorUsedError; } @@ -453,6 +471,8 @@ class __$$OnMutativeRequestSuccessImplCopyWithImpl<$Res> $Res Function(_$OnMutativeRequestSuccessImpl) _then) : super(_value, _then); + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -491,7 +511,9 @@ class _$OnMutativeRequestSuccessImpl implements _OnMutativeRequestSuccess { @override int get hashCode => Object.hash(runtimeType, request); - @JsonKey(ignore: true) + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$OnMutativeRequestSuccessImplCopyWith<_$OnMutativeRequestSuccessImpl> @@ -580,8 +602,11 @@ abstract class _OnMutativeRequestSuccess implements SturdyHttpEvent { @override RequestOptions get request; + + /// Create a copy of SturdyHttpEvent + /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) _$$OnMutativeRequestSuccessImplCopyWith<_$OnMutativeRequestSuccessImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/pubspec.yaml b/pubspec.yaml index 2ce21af..6560da4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,23 +1,23 @@ name: sturdy_http description: A strongly typed, event-based, reliable HTTP client that wraps `Dio`. -version: 0.4.0 +version: 0.5.0-dev1 homepage: https://github.com/Betterment/sturdy_http repository: https://github.com/Betterment/sturdy_http environment: - sdk: ">=3.0.7 <4.0.0" + sdk: ">=3.5.0 <4.0.0" dependencies: - collection: ^1.17.1 - dio: ^5.2.0 - freezed_annotation: ^2.2.0 - uuid: ^4.1.0 + collection: ^1.19.0 + dio: ^5.7.0 + freezed_annotation: ^2.4.4 + uuid: ^4.5.0 dev_dependencies: - build_runner: ^2.1.8 - charlatan: 0.4.0 - freezed: ^2.2.0 - json_annotation: ^4.4.0 - json_serializable: ^6.1.5 - lints: ^3.0.0 - test: ^1.16.0 + build_runner: ^2.4.12 + charlatan: ^0.4.0 + freezed: ^2.5.7 + json_annotation: ^4.9.0 + json_serializable: ^6.8.0 + lints: ^4.0.0 + test: ^1.25.8 diff --git a/test/src/deserializer_test.dart b/test/src/deserializer_test.dart index f9452a8..6c6f858 100644 --- a/test/src/deserializer_test.dart +++ b/test/src/deserializer_test.dart @@ -21,7 +21,7 @@ void main() { return Foo(message: isolateName!); } - final response = NetworkResponse.ok(const Foo(message: '--').toJson()); + final response = OkResponse(const Foo(message: '--').toJson()); final subject = BackgroundDeserializer(); final result = await subject.deserialize( response: response, @@ -31,15 +31,15 @@ void main() { }); test('it handles multiple requests for deserialization', () async { - onResponse(NetworkResponse response) { - return response.maybeWhen( - ok: Foo.fromJson, - orElse: () => fail('orElse not expected'), - ); + Foo onResponse(NetworkResponse response) { + return switch (response) { + OkResponse(:final response) => Foo.fromJson(response), + _ => fail('Not expected: orElse'), + }; } - final responseOne = NetworkResponse.ok(const Foo(message: '1').toJson()); - final responseTwo = NetworkResponse.ok(const Foo(message: '2').toJson()); + final responseOne = OkResponse(const Foo(message: '1').toJson()); + final responseTwo = OkResponse(const Foo(message: '2').toJson()); final subject = BackgroundDeserializer(); final resultOne = await subject.deserialize( response: responseOne, @@ -57,15 +57,13 @@ void main() { 'it throws CheckedFromJsonExceptions when deserialization issues occur', () async { onResponse(NetworkResponse response) { - return response.maybeWhen( - // Attempt to deserialize will fail because the response - // payload is a `Foo`, not a `NotFoo` - ok: NotFoo.fromJson, - orElse: () => fail('orElse not expected'), - ); + return switch (response) { + OkResponse(:final response) => NotFoo.fromJson(response), + _ => fail('orElse not expected'), + }; } - final response = NetworkResponse.ok(const Foo(message: 'Nope').toJson()); + final response = OkResponse(const Foo(message: 'Nope').toJson()); final subject = BackgroundDeserializer(); try { await subject.deserialize( diff --git a/test/src/sturdy_http_test.dart b/test/src/sturdy_http_test.dart index 9136678..de2a328 100644 --- a/test/src/sturdy_http_test.dart +++ b/test/src/sturdy_http_test.dart @@ -171,10 +171,10 @@ void main() { await buildSubject().execute( const GetRequest('/foo'), onResponse: (response) { - return response.maybeWhen( - ok: (response) => true, - orElse: () => false, - ); + return switch (response) { + OkResponse() => true, + _ => false, + }; }, ); expect(options.data, isNull); @@ -193,7 +193,7 @@ void main() { ), ), onResponse: (response) { - return response.maybeWhen(orElse: () => null); + return null; }, ); expect( @@ -218,7 +218,7 @@ void main() { options: Options(extra: {'foo': 'bar'}), ), onResponse: (response) { - return response.maybeWhen(orElse: () => null); + return null; }, ); expect( @@ -238,9 +238,7 @@ void main() { '/foo', queryParameters: {'foo': 'bar'}, ), - onResponse: (response) => response.maybeWhen( - orElse: () => null, - ), + onResponse: (response) {}, ); expect( options.queryParameters, @@ -255,19 +253,15 @@ void main() { test('request options contain correct method ', () async { await buildSubject().execute( const GetRequest('/foo'), - onResponse: (response) => response.maybeWhen( - orElse: () => null, - ), + onResponse: (response) {}, ); expect(options.method, 'GET'); - await buildSubject().execute( + await buildSubject().execute( const PostRequest( '/bar', data: NetworkRequestBody.empty(), ), - onResponse: (response) => response.maybeWhen( - orElse: () => null, - ), + onResponse: (response) {}, ); expect(options.method, 'POST'); }); @@ -304,11 +298,11 @@ void main() { await buildSubject().execute>( const GetRequest('/foo'), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(Foo.fromJson(json)), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(Foo.fromJson(response)), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -327,11 +321,11 @@ void main() { buildSubject().execute>( const GetRequest('/not-foo'), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(Foo.fromJson(json)), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(Foo.fromJson(response)), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -367,11 +361,10 @@ void main() { data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - okNoContent: () => const Result.success(true), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkNoContent() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -402,14 +395,15 @@ void main() { data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - genericError: (message, isConnectionIssue, error) { - expect(isConnectionIssue, isFalse); - return const Result.success(true); - }, - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + GenericError(:final isConnectionIssue) => () { + { + expect(isConnectionIssue, isFalse); + return const Result.success(true); + } + }(), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -456,43 +450,43 @@ void main() { () async { final subject = buildSubject(); await Future.wait([ - subject.execute>( + subject.execute>( const PostRequest( '/foo', data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(json['foo'] as String), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(response['foo'] as String), + _ => const Result.failure('Not expected: orElse'), + }; }, ), - subject.execute>( + subject.execute>( const PutRequest( '/bar', data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(json['foo'] as String), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(response['foo'] as String), + _ => const Result.failure('Not expected: orElse'), + }; }, ), - subject.execute>( + subject.execute>( const DeleteRequest( '/baz', data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(json['foo'] as String), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(response['foo'] as String), + _ => const Result.failure('Not expected: orElse'), + }; }, ), ]); @@ -543,43 +537,43 @@ void main() { () async { final subject = buildSubject(); await Future.wait([ - subject.execute>( + subject.execute>( const PostRequest( '/foo', data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(json['foo'] as String), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(response['foo'] as String), + _ => const Result.failure('Not expected: orElse'), + }; }, ), - subject.execute>( + subject.execute>( const PutRequest( '/bar', data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(json['foo'] as String), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(response['foo'] as String), + _ => const Result.failure('Not expected: orElse'), + }; }, ), - subject.execute>( + subject.execute>( const DeleteRequest( '/baz', data: NetworkRequestBody.empty(), ), onResponse: (response) { - return response.maybeWhen( - ok: (json) => Result.success(json['foo'] as String), - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + OkResponse(:final response) => + Result.success(response['foo'] as String), + _ => const Result.failure('Not expected: orElse'), + }; }, ), ]); @@ -618,10 +612,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeMap( - unauthorized: (request) => const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + Unauthorized() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -644,10 +638,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - forbidden: (request) => const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + Forbidden() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -668,10 +662,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - notFound: (request) => const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + NotFound() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -695,11 +689,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - unprocessableEntity: (error, response) => - const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + UnprocessableEntity() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -723,10 +716,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - upgradeRequired: (error) => const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + UpgradeRequired() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -747,10 +740,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - serverError: (request) => const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + ServerError() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -771,10 +764,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - serviceUnavailable: (request) => const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + ServiceUnavailable() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -795,11 +788,10 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - genericError: (message, _, error) => - const Result.success(true), - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + GenericError() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -824,13 +816,15 @@ void main() { await buildSubject().execute>( const GetRequest(defaultPath), onResponse: (response) { - return response.maybeWhen( - genericError: (message, isConnectionIssue, error) { - expect(isConnectionIssue, isTrue); - return const Result.success(true); - }, - orElse: () => const Result.failure('Not expected: orElse'), - ); + return switch (response) { + GenericError(:final isConnectionIssue) => () { + { + expect(isConnectionIssue, isTrue); + return const Result.success(true); + } + }(), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -863,13 +857,10 @@ void main() { ), ), onResponse: (response) { - return response.maybeWhen( - genericError: (_, __, ___) { - return const Result.success(true); - }, - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + GenericError() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -903,13 +894,10 @@ void main() { retryBehavior: NeverRetry(), ), onResponse: (response) { - return response.maybeWhen( - genericError: (_, __, ___) { - return const Result.success(true); - }, - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + GenericError() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -946,13 +934,10 @@ void main() { ), ), onResponse: (response) { - return response.maybeWhen( - genericError: (_, __, ___) { - return const Result.success(true); - }, - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + GenericError() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); @@ -994,13 +979,10 @@ void main() { ), ), onResponse: (response) { - return response.maybeWhen( - genericError: (_, __, ___) { - return const Result.success(true); - }, - orElse: () => - const Result.failure('Not expected: orElse'), - ); + return switch (response) { + GenericError() => const Result.success(true), + _ => const Result.failure('Not expected: orElse'), + }; }, ); diff --git a/test/src/sturdy_http_test.freezed.dart b/test/src/sturdy_http_test.freezed.dart index 14704cd..c0d3331 100644 --- a/test/src/sturdy_http_test.freezed.dart +++ b/test/src/sturdy_http_test.freezed.dart @@ -72,6 +72,9 @@ class _$ResultCopyWithImpl> final $Val _value; // ignore: unused_field final $Res Function($Val) _then; + + /// Create a copy of Result + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @@ -91,6 +94,8 @@ class __$$SuccessImplCopyWithImpl _$SuccessImpl _value, $Res Function(_$SuccessImpl) _then) : super(_value, _then); + /// Create a copy of Result + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -130,7 +135,9 @@ class _$SuccessImpl implements _Success { int get hashCode => Object.hash(runtimeType, const DeepCollectionEquality().hash(success)); - @JsonKey(ignore: true) + /// Create a copy of Result + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$SuccessImplCopyWith> get copyWith => @@ -203,7 +210,10 @@ abstract class _Success implements Result { const factory _Success(final S success) = _$SuccessImpl; S get success; - @JsonKey(ignore: true) + + /// Create a copy of Result + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) _$$SuccessImplCopyWith> get copyWith => throw _privateConstructorUsedError; } @@ -225,6 +235,8 @@ class __$$FailureImplCopyWithImpl _$FailureImpl _value, $Res Function(_$FailureImpl) _then) : super(_value, _then); + /// Create a copy of Result + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -264,7 +276,9 @@ class _$FailureImpl implements _Failure { int get hashCode => Object.hash(runtimeType, const DeepCollectionEquality().hash(failure)); - @JsonKey(ignore: true) + /// Create a copy of Result + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$FailureImplCopyWith> get copyWith => @@ -337,7 +351,10 @@ abstract class _Failure implements Result { const factory _Failure(final F failure) = _$FailureImpl; F get failure; - @JsonKey(ignore: true) + + /// Create a copy of Result + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) _$$FailureImplCopyWith> get copyWith => throw _privateConstructorUsedError; } @@ -350,8 +367,12 @@ Foo _$FooFromJson(Map json) { mixin _$Foo { String get message => throw _privateConstructorUsedError; + /// Serializes this Foo to a JSON map. Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) + + /// Create a copy of Foo + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) $FooCopyWith get copyWith => throw _privateConstructorUsedError; } @@ -372,6 +393,8 @@ class _$FooCopyWithImpl<$Res, $Val extends Foo> implements $FooCopyWith<$Res> { // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of Foo + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -401,6 +424,8 @@ class __$$FooImplCopyWithImpl<$Res> extends _$FooCopyWithImpl<$Res, _$FooImpl> __$$FooImplCopyWithImpl(_$FooImpl _value, $Res Function(_$FooImpl) _then) : super(_value, _then); + /// Create a copy of Foo + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -439,11 +464,13 @@ class _$FooImpl implements _Foo { (identical(other.message, message) || other.message == message)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, message); - @JsonKey(ignore: true) + /// Create a copy of Foo + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$FooImplCopyWith<_$FooImpl> get copyWith => @@ -464,8 +491,11 @@ abstract class _Foo implements Foo { @override String get message; + + /// Create a copy of Foo + /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) _$$FooImplCopyWith<_$FooImpl> get copyWith => throw _privateConstructorUsedError; } @@ -478,8 +508,12 @@ NotFoo _$NotFooFromJson(Map json) { mixin _$NotFoo { String get notMessage => throw _privateConstructorUsedError; + /// Serializes this NotFoo to a JSON map. Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) + + /// Create a copy of NotFoo + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) $NotFooCopyWith get copyWith => throw _privateConstructorUsedError; } @@ -501,6 +535,8 @@ class _$NotFooCopyWithImpl<$Res, $Val extends NotFoo> // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of NotFoo + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -533,6 +569,8 @@ class __$$NotFooImplCopyWithImpl<$Res> _$NotFooImpl _value, $Res Function(_$NotFooImpl) _then) : super(_value, _then); + /// Create a copy of NotFoo + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -572,11 +610,13 @@ class _$NotFooImpl implements _NotFoo { other.notMessage == notMessage)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, notMessage); - @JsonKey(ignore: true) + /// Create a copy of NotFoo + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$NotFooImplCopyWith<_$NotFooImpl> get copyWith => @@ -597,8 +637,11 @@ abstract class _NotFoo implements NotFoo { @override String get notMessage; + + /// Create a copy of NotFoo + /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) _$$NotFooImplCopyWith<_$NotFooImpl> get copyWith => throw _privateConstructorUsedError; }