Cra sh при вызове Promise.resolve вот мой код:
@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);
}
});
}
Это функция getDataInflate:
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;
}
}
Это функция jsonToReact:
public static WritableMap jsonToReact(String mJson) {
WritableMap mWrite = Arguments.createMap();
mWrite.putString("body", mJson);
mWrite.putString("message", "Fetch data success");
return mWrite;
}
Я использую центр приложений для обнаружения cra sh log:
com.facebook.react.bridge.WritableNativeArray.pushNativeMap
WritableNativeArray.java, line -2
com.facebook.react.bridge.ObjectAlreadyConsumedException: Map already consumed
трассировка стека: [1]: https://i.stack.imgur.com/opVDx.png
Моя библиотека - это RNInflateModule, строка 63 вызывает обещание.resolve в onResponse, которое я публикую в методе get () выше. Я использую 0.59.9.