
Hi i have a function that should create a team. The function triggers correctly. And the loggs show this. Trying to create team for user 15907099529 with name FriendsOf-Test Error creating team for user 15907099529 with name FriendsOf-Test {}
Why to the logs not show what the error is. I am a bit stuck on that to do. I have included my code for help.
try {
console.log(`Trying to create team for user ${UserId} with name-${UserId}`);
const teamCreateResponse = await teams.create(UserId, UserId);
console.log("Team created successfully!");
console.log(teamCreateResponse);
res.json({
success: true,
response: teamCreateResponse,
});
} catch (teamErrorResponse) {
console.log(`Error creating team for user ${UserId} with name-${UserId}`);
console.log(teamErrorResponse);
res.json({
success: false,
response: teamErrorResponse,
});
}

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Try to wrap the error with str()

I have tried but i dont think its initialised.
console.log(`Error- ${JSON.stringify(teamErrorResponse)}`);

I have `thrown the error now with this
throw new Error(`Error- ${JSON.stringify(teamErrorResponse)}`);
and i get
Error: Error- {}
at module.exports (/usr/code-start/src/index.js:92:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /usr/local/src/server.js:68:13

Make sure your code doesn't throw any exceptions.

Don't stringify the error like that. Just str(error)

} catch (teamErrorResponse) {
console.log(`Error creating team for user ${UserId} with name-${UserId}`);
console.log(teamErrorResponse);
console.log(str(teamErrorResponse));
res.json({
success: false,
response: teamErrorResponse,
});
}
I have tried like you suggested and added str but this is not defined
ReferenceError: str is not defined at module.exports (/usr/code-start/src/index.js:94:13) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async /usr/local/src/server.js:68:13

} catch (teamErrorResponse) {
console.log(`Error creating team for user ${UserId} with name-${UserId}`);
console.log(teamErrorResponse);
console.log(String(teamErrorResponse));
res.json({
success: false,
response: teamErrorResponse,
});
}
I have tried altering your suggestion and added String(teamErrorResponse) This get me an error.
Error: connect ECONNREFUSED 127.0.0.1:80

This is very odd to me as when i do a simulated function call with.. "test": "node src/test.js",
test.js (test only API key and user data)

const sdk = require("node-appwrite");
const testPoint = require("./index.js");
let req = {
"variables": {
"APPWRITE_FUNCTION_ENDPOINT": "http://localhost/v1",
"APPWRITE_FUNCTION_PROJECT_ID": "637fb4a92e46b8811264",
"APPWRITE_FUNCTION_API_KEY": "TESTKEY",
"APPWRITE_FUNCTION_ID": "645ea70bd2c181675e41",
"APPWRITE_FUNCTION_NAME": "NewUserTeam",
"APPWRITE_FUNCTION_DEPLOYMENT": "6461f70104ad3cd03ffe",
"APPWRITE_FUNCTION_TRIGGER": "event",
"APPWRITE_FUNCTION_RUNTIME_NAME": "Node.js",
"APPWRITE_FUNCTION_RUNTIME_VERSION": "16.0",
"APPWRITE_FUNCTION_EVENT": "users.6461f74228b337eba672.create",
"APPWRITE_FUNCTION_EVENT_DATA": "{\"$id\":\"6461f74228b337eba672\",\"$createdAt\":\"2023-05-15T09:11:30.235+00:00\",\"$updatedAt\":\"2023-05-15T09:11:30.235+00:00\",\"name\":\"Test USer\",\"password\":\"$argon2id$v=19$m=65536,t=4,p=3$elBkd0VKNWJlYXBXQ1pYUQ$LCHJpApaPHGe3gK\\/6Hqpg5y9KA25viQsvz4JFdfppOY\",\"hash\":\"argon2\",\"hashOptions\":{\"type\":\"argon2\",\"memoryCost\":2048,\"timeCost\":4,\"threads\":3},\"registration\":\"2023-05-15T09:11:30.235+00:00\",\"status\":true,\"passwordUpdate\":\"2023-05-15T09:11:30.235+00:00\",\"email\":\"test.user@testing.com\",\"phone\":\"+34234324\",\"emailVerification\":false,\"phoneVerification\":false,\"prefs\":[]}",
"APPWRITE_FUNCTION_DATA": "",
"APPWRITE_FUNCTION_USER_ID": "642a96237048b738abbe",
"APPWRITE_FUNCTION_JWT": ""
},
"headers": {},
"payload": ""
}
let res = { json: (data) => { console.log(data); } };
testPoint(req, res);

The code runs no problem with running the index.js from my host. As connection to appwrite backed in esablished and function finishes its work. The only difference i can think of is the docker container not being able to reach appwrite. Something there resulting in **Error: connect ECONNREFUSED 127.0.0.1:80 **

God sorry...I thought you were using python for some reason. It would be error.toString()
in JavaScript

No worries i appreciate any help i can get 🙂

You can't use localhost in functions because the runtime container will try to connect to itself rather than Appwrite. You can try using the LAN IP of your machine if you're developing locally

Ok so change my APPWRITE_FUNCTION_ENDPOINT variable to my local lan ip?

I will give that a go. Thankyou. I am going through the docs to upgrade to 1.3.4 now but will update when findings when done.

Thankyou @Steven changing the APPWRITE_FUNCTION_ENDPOINT to the local ip worked. Thanks a lot. Did notice however that the users..create trigger was working ONLY with default signup but not from oAuth as described in Issue 5198 . Using the users..sessions..create as workaround for now.

[SOLVED] Function Errors
Recommended threads
- Where is tensorflow support? 3.11 ML doe...
and if i manually tried to add tensorflow i get Cannot access offset of type string on string no matter what
- OAuth2 Error: invalid success param url ...
Hi everyone! I'm trying to implement Google OAuth2 login in a React Native app (using the Android simulator) with Appwrite Cloud, and I'm getting the following ...
- Trying to set up a new appwrite project
we have used the folder structure as follow Functions /function-name /src/index,js This is our entrypoint and git confugre settings When I try to run ...
