Back

FormatException: SyntaxError: Unexpected end of JSON input

  • 0
  • Flutter
  • Functions
rosario
25 Apr, 2024, 13:16

Hello guys,

I run an execution Execution execution = await functions.getExecution( functionId: functionId, executionId: executionId); which call the Completation Chat API from OpenAI.

Since it took more than 30 seconds and I got the error Operation timed out after 30000 milliseconds

So I defined an async function:

`Execution result = await functions.createExecution( functionId: '65fd719a000f460e4896', body: body, method: 'POST', headers: headers, xasync: true);

TypeScript
  var executionId = result.$id;

  Execution execution = await functions.getExecution(
      functionId:functionId, executionId: executionId);

  while (
      execution.status == 'waiting' || execution.status == 'processing') {
    await Future.delayed(Duration(seconds: 5));

    execution = await functions.getExecution(
        functionId: functionId, executionId: executionId);
  }`

The function is completed but I get the following error FormatException: SyntaxError: Unexpected end of JSON input

TypeScript
  print(result.responseBody); does not print anything but I can see in the Admin console the body printed which is a valid JSON.

Why do I have the problem?

TL;DR
Developers are encountering a `FormatException` with the message `SyntaxError: Unexpected end of JSON input` when trying to utilize the Completation Chat API from OpenAI. This occurs despite receiving a valid JSON response. The issue might be due to asynchronous operations. Possible Solution: Make sure that the API response is being fully received before attempting to parse it. Consider checking the response content length or using a delay to allow for the complete reception of JSON data before processing it.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more