Back

getting same response for every separate request to cloud function

  • 0
  • Functions
dammy
8 Jul, 2023, 10:37

kindly assist if you're chanced

TL;DR
The user is experiencing an issue where they are getting the same response for every separate request to a cloud function. They have discovered that the issue is with their code's logic. The user provides the code they are using. One suggestion is to add print statements to confirm the data is coming in and going out correctly. The user asks if Appwrite caches requests, but it is unclear if this is the case. The user shares server-side and client-side code. They are receiving the same response despite making separate requests. The user is asked to check the Appwrite console to see if the executions show the same response. No solution is provided in
rohit90314
8 Jul, 2023, 13:50

Can you check the appwrite console and see if those executions show same response?

dammy
8 Jul, 2023, 14:58

okay then

dammy
8 Jul, 2023, 15:01

response on client app is same with appwrite console response

@rohit90314

dammy
8 Jul, 2023, 15:01

below is the response:

TypeScript
{"Status":"M S- yam"}

despite having separate resquest, response is same...

Drake
8 Jul, 2023, 17:00

Please don't tag people just because you need help. Please be patient and wait for a response

Drake
8 Jul, 2023, 17:01

Please share your code

dammy
8 Jul, 2023, 20:26

ok

dammy
8 Jul, 2023, 20:27

serverside or clientside?

dammy
8 Jul, 2023, 20:28

user side:

TypeScript
dynamic execution = appWriteLogicExtender.functions.createExecution(
          functionId: 'automate_service_sender_', data: json.encode(data));
      //  showloader = true
      showLoaderUpdater(true);
      if (kDebugMode) {
        print("What is sent to server: ${data.toString()}");
      }
      execution.then((response) {
        // show loader = false
        showLoaderUpdater(false);
        final decoded = json.decode(response.response);
          print("What is gotten from server: ${decoded.toString()}");

});
dammy
8 Jul, 2023, 20:32

server side:

TypeScript
Future<void> start(final req, final res) async {
  final client = Client();


  // // ////////////////////////////////

  client
      .setEndpoint("xxx")
      .setProject("xxx")
      .setKey("xxx")
      .setSelfSigned(status: true);

  dataFromClient = await jsonDecode(req.payload);
  res.json({
          'Status': getResp.toString(),
        });
}```

there are other part of the code and it returns a string statement using the variable **getResp**


expecting separate response but getting same as though it is cached
dammy
8 Jul, 2023, 21:22

yes, returned getResp

Drake
8 Jul, 2023, 21:22

Something might be wrong with your logic then

dammy
8 Jul, 2023, 21:23

I crossed checked before asking for help

dammy
8 Jul, 2023, 21:23

but does appwrite cache request?

Drake
8 Jul, 2023, 21:23

No

Drake
8 Jul, 2023, 21:25

Add a print(req.payload) to confirm the data is coming in correctly. Add a print(getResp.toString()) before res.json() to confirm the data is going out correctly

dammy
8 Jul, 2023, 21:27
TypeScript
if (serciceTypeAndServiceName == "MTN SME") {
        if (isMTNSMEAvailable.toString() == "Automated") {
          x = "M S- yam";
}}
 else if (serciceTypeAndServiceName == "MTN CG") {
        if (isMTNCGAvailable == "Automated") {
          x = "M C- yam";
}
}```

content of code, I decided to say:
```dart
x = "M S- yam";

and

TypeScript
x = "M C- yam";

in place of main code function to see where error was and discovered there was same response for diffrent request

Drake
8 Jul, 2023, 21:28

Sorry I don't understand

dammy
8 Jul, 2023, 21:31

if request has "MTN SME" The response should be: x = "M S- yam";

and otherwise

but after gettin "M S- yam"; for the below: "MTN SME" I still get: "M S- yam" for the above reqeust: "MTN CG"

Drake
8 Jul, 2023, 21:33

Sorry you're going to have to debug your code yourself

dammy
8 Jul, 2023, 21:33

sighs

safwan
9 Jul, 2023, 08:52

it's unfortunate, but the problem seems to be in your code's logic. I can try to take a look. Please show the code for your full function.

dammy
9 Jul, 2023, 20:17

wow, I appreciate you @safwan

dammy
9 Jul, 2023, 20:19

I discovered the dart file holding all variables on cloud function code was the one caching it. So I had to dispose them and did a check before every request, I appreciate you @Steven @safwan

I was thinking that cloud function doesn't remember any data after execution, that's why my focus was on both ends

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