Back

Dart function custom statuscode

  • 0
  • Functions
  • Flutter
AmstruP
27 Jul, 2023, 20:54

Dear support

I am quite new into the programming world and I am trying to learn flutter/dart and Appwrite as a backend. I have written some functions in Dart but I cannot return any custom statusCode from the function. According to the open runtimes documentation, it should be possible by res.json({ 'areDevelopersAwesome': true, }, status: 500);

The function does always return statusCode 200 unless it fails.

I have looked into the container from open runtimes and found the two function_types.dart and server.dart at usr/local/src but when I compare those files to the files at open runtimes Github (https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/dart-2.17/src) they are completely different.

Do you know how I can make the custom statusCode work in dart functions?

TL;DR
The user is having trouble returning a custom statusCode from a Dart function in Appwrite. They have looked into the container from open runtimes but found that the files there are different from the files on the open runtimes GitHub. The support suggests not trying to send a custom statusCode and instead ensuring that the code runs successfully and returns a 200 status. Solution: Try to make sure the code runs successfully and returns a 200 status instead of trying to send a custom statusCode.
Drake
27 Jul, 2023, 21:20

ya...for now, i highly recommend not trying to send a custom status code. you should always try to make sure your code runs successfully (and returns a 200 status).

Drake
27 Jul, 2023, 21:21

this is because if your open runtimes function returns a failure, Appwrite might not process it correctly so you won't see anything in logs or errors in Appwrite

AmstruP
27 Jul, 2023, 21:22

Hi Steven Thanks for the reply. I only want to throw some Exceptions if some criteria is missing in the function. That is why I wanted to use the custom status code. Do you know why the files from the open runtime repo is not identical with the files in the container?

Drake
27 Jul, 2023, 21:26

I only want to throw some Exceptions if some criteria is missing in the function.

Your function code should make sure to not throw any exception (so catch all exceptions).

Do you know why the files from the open runtime repo is not identical with the files in the container?

They are the same. It's just Appwrite might not handle the error like you want

Drake
27 Jul, 2023, 21:27

the common approach is to have your function just return status 200 but have a status value in the response to check if the execution itself was successful or not

AmstruP
27 Jul, 2023, 21:29

Okay, I see. Thanks for the explanation.

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