Skip to content

Commit

Permalink
fix(supabase): include request in generic error to handle offline ups…
Browse files Browse the repository at this point in the history
…ert #439
  • Loading branch information
tshedor committed Sep 13, 2024
1 parent 14a1c41 commit be57e16
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/brick_offline_first_with_rest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 3.1.0

- Expose offline queue functionality in `offline_queue.dart`
- Include `request` in `RestOfflineQueueClient`'s generic error response

## 3.0.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class RestOfflineQueueClient extends http.BaseClient {
final genericErrorResponse = http.StreamedResponse(
Stream.fromFuture(Future.value('unknown internal error'.codeUnits)),
501,
request: request,
);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:brick_supabase/brick_supabase.dart';
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';
import 'package:sqflite_common/sqlite_api.dart' show DatabaseFactory;
import 'package:supabase/supabase.dart';

/// Ensures the [remoteProvider] is a [SupabaseProvider].
///
Expand Down Expand Up @@ -79,6 +80,25 @@ abstract class OfflineFirstWithSupabaseRepository
await offlineRequestQueue.client.requestManager.migrate();
}

@override
Future<TModel> upsert<TModel extends OfflineFirstWithSupabaseModel>(
TModel instance, {
OfflineFirstUpsertPolicy policy = OfflineFirstUpsertPolicy.optimisticLocal,
Query? query,
}) async {
try {
return await super.upsert<TModel>(instance, policy: policy, query: query);
} on PostgrestException catch (e) {
logger.warning('#upsert supabase failure: $e');

if (policy == OfflineFirstUpsertPolicy.requireRemote) {
throw OfflineFirstException(Exception(e));
}

return instance;
}
}

/// This is a convenience method to create the basic offline client and queue.
/// The client is used to add offline capabilities to [SupabaseProvider];
/// the queue is used to add offline to the repository.
Expand All @@ -96,7 +116,6 @@ abstract class OfflineFirstWithSupabaseRepository
409,
429,
500,
501,
502,
503,
504,
Expand Down

0 comments on commit be57e16

Please sign in to comment.