how to receive the string in the client. the cloud function returns as "return context.res.send("Hello, World!");"
unable to retrieve the error code from the cloud function captured during the execution inside the cloud server.
You need to return the error to the client?
Have you tried: return context.res.send(error.message)?
yes
final execution = await functions.createExecution(functionId: '65211abe4aade6923e7c', body: jsontestnew);
this funtion creates new user
function is working fine
i want to receive the error.message in the client
this is the exception object string when error occurs.
{$id: 65219a57e8f7da6b8c4f, $createdAt: 2023-10-07T17:50:19.578+00:00, $updatedAt: 2023-10-07T17:50:19.578+00:00, $permissions: [read("user:64d6987a54e50a844777")], functionId: 65211abe4aade6923e7c, trigger: http, status: failed, requestMethod: POST, requestPath: /, requestHeaders: [], responseStatusCode: 500, responseBody: , responseHeaders: [{name: x-powered-by, value: Dart with package:shelf}, {name: date, value: Sat, 07 Oct 2023 17:50:19 GMT}, {name: content-length, value: 0}, {name: x-frame-options, value: SAMEORIGIN}, {name: content-type, value: text/plain; charset=utf-8}, {name: x-xss-protection, value: 1; mode=block}, {name: x-content-type-options, value: nosniff}], logs: , errors: , duration: 2.8738858699798584}
i want this message "AppwriteException: user_already_exists, A user with the same id, email, or phone already exists in this project. (409)". to be received from client
can you post your function method, you just need to propogate the message properly to client.
a general idea like this can be used -
export default async function (context) {
let message;
try {
await createUser();
// no exception, it worked
message = "success"
} catch(error) {
message = error.message;
}
return context.res.send(message);
}
Client side: let message = executionStatus?.responseBody.
responseBody is empty
when user creation failed responseBody is empty
on sucess responseBody is user object
Future result = users.create( userId: data.userid!, //'[USER_ID]', email: data.email!, //'email@example.com', password: data.passw!, //'password', phone: data.phone, //'phone', name: data.name, //'phone', );
User mm = await result;
return context.res.send(mm.toMap().toString());
} catch (e) { //print(e.toString()); context.error("Failed to create user " + e.toString());
return context.res.send('error:' + e.toString());
}
this is the error log
Failed to create user AppwriteException: user_already_exists, A user with the same id, email, or phone already exists in this project. (409) Execution timed out.
i returned the context.res.send from the catch block. that's the problem. Now i changed to return from --outside the try/catch block. function works correctly.
received the message through executionStatus?.responseBody.
😀 thank you
[solved] receive context.res.send from client
Recommended threads
- executeFunction intermittently throws Fo...
Environment: Flutter app using the Appwrite Flutter SDK, calling executeFunction for [describe endpoint, e.g. live-stream-related function]. *Description*: Int...
- How to update from 1.8.1 to 1.9.6
Due to the number of issues reported in version 1.9.5, I am hesitant to proceed with the update. Could anyone advise if version 1.9.6 is stable and resolves tho...
- HTTP Error 500 ''
Hello to everyone, I'm a Flutter developer and actually I'm developing an app using Appwrite.. during my tests and also massive ones I've noticed something we...