Skip to content

Commit 93765ae

Browse files
committed
chore: Add comment docs for errorTrigger
1 parent 4e8d490 commit 93765ae

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/src/mock_supabase_http_client.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ class MockSupabaseHttpClient extends BaseClient {
1313
dynamic Function(Map<String, dynamic>? params,
1414
Map<String, List<Map<String, dynamic>>> tables)> _rpcFunctions = {};
1515

16+
/// A function that can be used to trigger errors.
17+
///
18+
/// Throw a PostgrestException within the `errorTrigger` to mock an error.
19+
///
20+
/// Example:
21+
/// ```dart
22+
/// final client = MockSupabaseHttpClient(
23+
/// errorTrigger: (schema, table, data, type) {
24+
/// if (table == 'users' && type == RequestType.insert) {
25+
/// throw PostgrestException(
26+
/// message: 'Email already exists', // Provide a message
27+
/// code: '400', // Optionally provide a status code
28+
/// details: 'Key (email)=([email protected]) already exists', // Optionally provide details
29+
/// hint: 'Change the email address', // Optionally provide a hint
30+
/// );
31+
/// }
32+
/// // The request will succeed otherwise
33+
/// },
34+
/// );
35+
/// ```
1636
final void Function(
1737
String schema,
1838
String? table,
@@ -28,6 +48,7 @@ class MockSupabaseHttpClient extends BaseClient {
2848
_rpcHandler = RpcHandler(_rpcFunctions, _database);
2949
}
3050

51+
/// Clears the mock database and RPC functions.
3152
void reset() {
3253
// Clear the mock database and RPC functions
3354
_database.clear();

0 commit comments

Comments
 (0)