@@ -6,6 +6,7 @@ import 'dart:core';
66
77import 'package:http/http.dart' as http;
88import 'package:http/http.dart' ;
9+ import 'package:logging/logging.dart' ;
910import 'package:meta/meta.dart' ;
1011import 'package:postgrest/postgrest.dart' ;
1112import 'package:yet_another_json_isolate/yet_another_json_isolate.dart' ;
@@ -44,6 +45,7 @@ class PostgrestBuilder<T, S, R> implements Future<T> {
4445 final Client ? _httpClient;
4546 final YAJsonIsolate ? _isolate;
4647 final CountOption ? _count;
48+ final _log = Logger ('supabase.postgrest' );
4749
4850 PostgrestBuilder ({
4951 required Uri url,
@@ -132,6 +134,8 @@ class PostgrestBuilder<T, S, R> implements Future<T> {
132134 _headers['Content-Type' ] = 'application/json' ;
133135 }
134136 final bodyStr = jsonEncode (_body);
137+ _log.finer ("Request: $uppercaseMethod $_url " );
138+
135139 if (uppercaseMethod == METHOD_GET ) {
136140 response = await (_httpClient? .get ?? http.get )(
137141 _url,
@@ -203,14 +207,17 @@ class PostgrestBuilder<T, S, R> implements Future<T> {
203207 // Workaround for https://github.com/supabase/supabase-flutter/issues/560
204208 if (_maybeSingle && method.toUpperCase () == 'GET' && body is List ) {
205209 if (body.length > 1 ) {
206- throw PostgrestException (
210+ final exception = PostgrestException (
207211 // https://github.com/PostgREST/postgrest/blob/a867d79c42419af16c18c3fb019eba8df992626f/src/PostgREST/Error.hs#L553
208212 code: '406' ,
209213 details:
210214 'Results contain ${body .length } rows, application/vnd.pgrst.object+json requires 1 row' ,
211215 hint: null ,
212216 message: 'JSON object requested, multiple (or no) rows returned' ,
213217 );
218+
219+ _log.fine ('$exception for request $_url ' );
220+ throw exception;
214221 } else if (body.length == 1 ) {
215222 body = body.first;
216223 } else {
@@ -286,6 +293,8 @@ class PostgrestBuilder<T, S, R> implements Future<T> {
286293 );
287294 }
288295
296+ _log.fine ('$error for request $_url ' );
297+
289298 throw error;
290299 }
291300 }
0 commit comments