Crash when call promise.resolve, here is my code :
@ReactMethod
public void get(String url, ReadableMap headers, ReadableMap params, final Promise promise) throws IOException {
Request mRequest = this.mApiManager.get(url, headers, params);
mClient.newCall(mRequest).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
promise.reject(REQUEST_ERROR, e.getCause());
call.cancel();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
inflateData = mUtils.getDataInflate(response);
promise.resolve(inflateData);
}
});
}
This a getDataInflate function :
public WritableMap getDataInflate(Response res) {
try {
String validJson;
if (isZipped(res)) {
final InputStream in = res.body().byteStream();
Inflater deCompressor = new Inflater(true);
InflaterInputStream input = new InflaterInputStream(in, deCompressor);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int length;
BufferedInputStream b = new BufferedInputStream(input);
while ((length = b.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
validJson = new String(out.toByteArray(), "UTF-8");
} else {
validJson = res.body().string();
}
mapWrite = mHelper.jsonToReact(validJson);
mapWrite.putInt("statusCode", res.code());
return mapWrite;
} catch (Exception e) {
e.printStackTrace();
mapWrite = Arguments.createMap();
mapWrite.putString("message", e.getMessage());
}
return mapWrite;
}
}
This is jsonToReact function:
public static WritableMap jsonToReact(String mJson) {
WritableMap mWrite = Arguments.createMap();
mWrite.putString("body", mJson);
mWrite.putString("message", "Fetch data success");
return mWrite;
}
I use app center to detect crash log :
com.facebook.react.bridge.WritableNativeArray.pushNativeMap
WritableNativeArray.java, line -2
com.facebook.react.bridge.ObjectAlreadyConsumedException: Map already consumed
stack trace: [1]: https://i.stack.imgur.com/opVDx.png
My library is RNInflateModule, line 63 call promise.resolve in onResponse that method I post in get() method above. I'm using 0.59.9.