Skip to content

🐛 Bug Report: Functions Call "Body has already been consumed." (RN Web and iOS, Android not tested)  #50

@Bormy1996

Description

@Bormy1996

👟 Reproduction steps

With expo react-native, when i try using a selfhosted Function i'm getting the error "Response.json: Body has already been consumed" on sdk.js

I've created an Starter Function (Ping/Pong) on my selfhosted Appwrite Backend and a fresh expo project:

npx create-expo-app@latest .
npx expo install appwrite // this works when you import from "appwrite"
npx expo install react-native-appwrite react-native-url-polyfill // this doesnt seem to work when you import from "react-native-appwrite"

I've added an button just to test the function call:

import { Client, AppwriteException, ExecutionMethod, Functions } from "appwrite"; // works
//import { Client, AppwriteException, ExecutionMethod, Functions } from "react-native-appwrite"; // doesn't work

const client = new Client()
  .setEndpoint("<URL>")
  .setProject("<project>")
//.setPlatform("<plattform>") //only with react-native-appwrite

[...]

return (
      <Button
        onPress={() => {
          onPress();
        }}
      />
)

[...]

  async function onPress() {
    const functions = new Functions(client);
    var result = "" as any;
    try {
      result = await functions.createExecution(
        "<functionId>", // functionId
        "", // body (optional)
        false, // async (optional)
        "/ping", // path (optional)
        ExecutionMethod.GET
      );
    } catch (error: AppwriteException | unknown) {
      console.log(error);
    }

    console.log(result);
  }

Catched error: "AppwriteException: Response.json: Body has already been consumed." on \node_modules\react-native-appwrite\dist\esm\sdk.js -> Line 398 method call in class Client:

[...]
            try {
                let data = null;
                const response = yield fetch(url.toString(), options);
                const text = yield response.text();
                const warnings = response.headers.get('x-appwrite-warning');
                if (warnings) {
                    warnings.split(';').forEach((warning) => console.warn('Warning: ' + warning));
                }
                if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
                    data = yield response.json(); // ERROR HERE
                }
                else {
                    data = {
                        message: text
                    };
                }
[...]
            }
            catch (e) {
                if (e instanceof AppwriteException) {
                    throw e;
                }
                throw new AppwriteException(e.message);
            }
        });
    }

👍 Expected behavior

According to fetch documentation, a fetch response can only read once. The sdk shoud pass the response proper to the caller.

👎 Actual Behavior

Error: "AppwriteException: Response.json: Body has already been consumed." on \node_modules\react-native-appwrite\dist\esm\sdk.js -> Line 398 method call in class Client:

🎲 Appwrite version

Version 0.7.x

💻 Operating system

Linux

RN Web and iOS, Android not tested

🧱 Your Environment

Using selfhosted appwrite on docker, with react native expo.

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions