Skip to content

Commit

Permalink
feat: support retrying failed requests (#8)
Browse files Browse the repository at this point in the history
* chore: run codegen

* chore: update CI

* formatting

* feat: support retrying failed requests

* chore: format test dir

* chore: add test for RetryBehavior

* chore: add codecov.yml

* reorder status codes
  • Loading branch information
btrautmann authored Apr 2, 2024
1 parent 141820e commit 8c19dc0
Show file tree
Hide file tree
Showing 14 changed files with 856 additions and 406 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ jobs:
ci:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup dart
uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f # v1.5.0
with:
sdk: 3.0.7
sdk: 3.3.1

- name: Install dependencies
run: dart pub get

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

- name: Analyze project source
uses: invertase/github-action-dart-analyzer@1cda5922c6369263b1c7e2fbe281f69704f4d63e #v1.0.0

- name: Run tests and generate coverage report
run: ./tool/generate_code_coverage.sh

- uses: codecov/codecov-action@40a12dcee2df644d47232dde008099a3e9e4f865 #v3.1.2
with:
files: coverage/lcov.info
Expand All @@ -38,13 +45,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup dart
uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f # v1.5.0
with:
sdk: 3.0.7
sdk: 3.3.1

- name: Install dependencies
run: |
dart pub get
dart pub global activate pana
- name: Verify pub score
run: ./tool/verify_pub_score.sh
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linter:
- package_api_docs
- public_member_api_docs
- sort_pub_dependencies
- require_trailing_commas

analyzer:
language:
Expand Down
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore:
- "**/*.freezed.dart"
- "**/*.g.dart"
13 changes: 12 additions & 1 deletion lib/src/network_request.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dio/dio.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:sturdy_http/src/retry_behavior.dart';
import 'package:sturdy_http/sturdy_http.dart';

part 'network_request.freezed.dart';
Expand Down Expand Up @@ -30,6 +31,7 @@ abstract class NetworkRequest {
this.cancelToken,
this.onReceiveProgress,
this.onSendProgress,
this.retryBehavior = const Unspecified(),
});

/// {@macro network_request_type}
Expand All @@ -38,7 +40,7 @@ abstract class NetworkRequest {
/// The path of the requested resource
final String path;

///
/// The body of the network request
final NetworkRequestBody data;

/// Whether this request should be considered as mutative. If false,
Expand All @@ -60,6 +62,10 @@ abstract class NetworkRequest {

/// [ProgressCallback] for send progress for this request
final ProgressCallback? onSendProgress;

/// The [RetryBehavior] for this request. Defaults to [Unspecified]. If not
/// overridden, the [SturdyHttp] instance's [RetryBehavior] will be used.
final RetryBehavior retryBehavior;
}

/// {@template get_request}
Expand All @@ -75,6 +81,7 @@ class GetRequest extends NetworkRequest {
super.cancelToken,
super.onReceiveProgress,
super.onSendProgress,
super.retryBehavior,
}) : super(
type: NetworkRequestType.Get,
path: path,
Expand All @@ -97,6 +104,7 @@ class PostRequest extends NetworkRequest {
super.cancelToken,
super.onReceiveProgress,
super.onSendProgress,
super.retryBehavior,
}) : super(
type: NetworkRequestType.Post,
path: path,
Expand All @@ -118,6 +126,7 @@ class PutRequest extends NetworkRequest {
super.cancelToken,
super.onReceiveProgress,
super.onSendProgress,
super.retryBehavior,
}) : super(
type: NetworkRequestType.Put,
path: path,
Expand All @@ -139,6 +148,7 @@ class DeleteRequest extends NetworkRequest {
super.cancelToken,
super.onReceiveProgress,
super.onSendProgress,
super.retryBehavior,
}) : super(
type: NetworkRequestType.Delete,
path: path,
Expand All @@ -163,6 +173,7 @@ class RawRequest extends NetworkRequest {
super.cancelToken,
super.onReceiveProgress,
super.onSendProgress,
super.retryBehavior,
}) : super(
path: path,
queryParams: queryParameters,
Expand Down
32 changes: 16 additions & 16 deletions lib/src/network_request.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part of 'network_request.dart';
T _$identity<T>(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#custom-getters-and-methods');
'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 _$NetworkRequestBody {
Expand Down Expand Up @@ -64,18 +64,18 @@ mixin _$NetworkRequestBody {

/// @nodoc
class _$_Empty implements _Empty {
const _$_Empty();
class _$EmptyImpl implements _Empty {
const _$EmptyImpl();

@override
String toString() {
return 'NetworkRequestBody.empty()';
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$_Empty);
(other.runtimeType == runtimeType && other is _$EmptyImpl);
}

@override
Expand Down Expand Up @@ -151,13 +151,13 @@ class _$_Empty implements _Empty {
}

abstract class _Empty implements NetworkRequestBody {
const factory _Empty() = _$_Empty;
const factory _Empty() = _$EmptyImpl;
}

/// @nodoc
class _$_Json implements _Json {
const _$_Json(final Map<String, dynamic> data) : _data = data;
class _$JsonImpl implements _Json {
const _$JsonImpl(final Map<String, dynamic> data) : _data = data;

final Map<String, dynamic> _data;
@override
Expand All @@ -173,10 +173,10 @@ class _$_Json implements _Json {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Json &&
other is _$JsonImpl &&
const DeepCollectionEquality().equals(other._data, _data));
}

Expand Down Expand Up @@ -254,15 +254,15 @@ class _$_Json implements _Json {
}

abstract class _Json implements NetworkRequestBody {
const factory _Json(final Map<String, dynamic> data) = _$_Json;
const factory _Json(final Map<String, dynamic> data) = _$JsonImpl;

Map<String, dynamic> get data;
}

/// @nodoc
class _$_Raw implements _Raw {
const _$_Raw(this.data);
class _$RawImpl implements _Raw {
const _$RawImpl(this.data);

@override
final Object? data;
Expand All @@ -273,10 +273,10 @@ class _$_Raw implements _Raw {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Raw &&
other is _$RawImpl &&
const DeepCollectionEquality().equals(other.data, data));
}

Expand Down Expand Up @@ -354,7 +354,7 @@ class _$_Raw implements _Raw {
}

abstract class _Raw implements NetworkRequestBody {
const factory _Raw(final Object? data) = _$_Raw;
const factory _Raw(final Object? data) = _$RawImpl;

Object? get data;
}
Loading

0 comments on commit 8c19dc0

Please sign in to comment.