File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
packages/powersync/lib/src Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -353,7 +353,7 @@ HttpException getError(http.Response response) {
353353 try {
354354 final body = response.body;
355355 final decoded = convert.jsonDecode (body);
356- final details = decoded['error' ]? ['details' ]? [ 0 ] ?? body;
356+ final details = stringOrFirst ( decoded['error' ]? ['details' ]) ?? body;
357357 final message = '${response .reasonPhrase ?? "Request failed" }: $details ' ;
358358 return HttpException (message, uri: response.request? .url);
359359 } on Error catch (_) {
@@ -366,11 +366,23 @@ Future<HttpException> getStreamedError(http.StreamedResponse response) async {
366366 try {
367367 final body = await response.stream.bytesToString ();
368368 final decoded = convert.jsonDecode (body);
369- final details = decoded['error' ]? ['details' ]? [ 0 ] ?? body;
369+ final details = stringOrFirst ( decoded['error' ]? ['details' ]) ?? body;
370370 final message = '${response .reasonPhrase ?? "Request failed" }: $details ' ;
371371 return HttpException (message, uri: response.request? .url);
372372 } on Error catch (_) {
373373 return HttpException (response.reasonPhrase ?? "Request failed" ,
374374 uri: response.request? .url);
375375 }
376376}
377+
378+ String ? stringOrFirst (Object ? details) {
379+ if (details == null ) {
380+ return null ;
381+ } else if (details is String ) {
382+ return details;
383+ } else if (details is List <String >) {
384+ return details[0 ];
385+ } else {
386+ return null ;
387+ }
388+ }
You can’t perform that action at this time.
0 commit comments