Skip to content

Commit

Permalink
Convert a java.lang.OutOfMemoryError into a ClientException
Browse files Browse the repository at this point in the history
Fixes #1271
  • Loading branch information
brianquinlan committed Aug 28, 2024
1 parent 7f21111 commit 09d8c55
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkgs/cronet_http/lib/src/cronet_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,19 @@ class CronetClient extends BaseClient {
headers.forEach((k, v) => builder.addHeader(k.toJString(), v.toJString()));

if (body.isNotEmpty) {
final JByteBuffer data;
try {
data = body.toJByteBuffer();
} on JniException catch (e) {
if (e.message.contains('java.lang.OutOfMemoryError:')) {
throw ClientException(
'Not enough memory for request body: ${e.message}', request.url);
}
rethrow;
}

builder.setUploadDataProvider(
jb.UploadDataProviders.create2(body.toJByteBuffer()), _executor);
jb.UploadDataProviders.create2(data), _executor);
}
builder.build().start();
return responseCompleter.future;
Expand Down

0 comments on commit 09d8c55

Please sign in to comment.