Back

Functions SDK Error handler

  • 0
  • Functions
Drake
4 Jul, 2023, 22:02

What exactly was the trace?

Did you see the execution start in the Appwrite console?

TL;DR
Summary: The user is discussing an error they encountered with a Functions SDK. They mention that they need to receive a certain header in order to confirm a message's origin. They also mention that when an error occurs, they only see a generic "Internal Server Error" message in the Appwrite function's dashboard. They are looking for a solution to these issues. Solution: It is recommended to catch exceptions and include more detailed error messages in the response. Additionally, the user should ensure they properly initialize and deploy their function. They can also create a function to reproduce the issue for further investigation.
Lucas Reis
8 Jul, 2023, 01:31

sorry, I have deleted the function and rewrote it using the Deno SDK. But what does happen on every script I write is, if it throws and error, I will see only an "Internal Server Error" message in the Error tab of the appwrite function's dashboard.

Lucas Reis
8 Jul, 2023, 01:34

for the error I was having the error message was empty. The only information I had was that it happened in the function that tries to make a request to execute the function I requested in the appwrite's api.

Lucas Reis
8 Jul, 2023, 01:34

gonna create a function to reproduce the issue for ya

Lucas Reis
8 Jul, 2023, 01:37

it didn't work with the Deno's SDK either though, I had to do a workaround that would cost me more one request xD

Lucas Reis
18 Jul, 2023, 04:05

Just an example

Lucas Reis
18 Jul, 2023, 04:05

sorry for taking too long

Lucas Reis
18 Jul, 2023, 04:06
TypeScript
/*
  'req' variable has:
    'headers' - object with request headers
    'payload' - request body data as a string
    'variables' - object with function variables

  'res' variable has:
    'send(text, status)' - function to return text response. Status code defaults to 200
    'json(obj, status)' - function to return JSON response. Status code defaults to 200

  If an error is thrown, a response with code 500 will be returned.
*/
export default async function (request: any, response: any) {
    throw new Error(
        'Environment variables are not set. Function cannot use Appwrite SDK.',
    )
}
Lucas Reis
18 Jul, 2023, 04:07

and this is what I get in the errors tab

Lucas Reis
18 Jul, 2023, 04:08

if I don't catch the error and send it in the response, I'll have no idea of what went wrong xD

Drake
18 Jul, 2023, 04:09

For now, it's best to always make sure you catch exceptions and return a response

Drake
18 Jul, 2023, 04:11

How did you initialize and deploy your function?

Lucas Reis
18 Jul, 2023, 04:12

appwrite init function

Lucas Reis
18 Jul, 2023, 04:12

appwrite deploy function

Lucas Reis
18 Jul, 2023, 04:13

one important thing I gotta ask you though is: do you know why the headers variable may be empty?

Lucas Reis
18 Jul, 2023, 04:13

I tried Deno and PHP SDK's

Lucas Reis
18 Jul, 2023, 04:13

I always get an empty array

Drake
18 Jul, 2023, 04:14

Yes, they're always empty

Lucas Reis
18 Jul, 2023, 04:14

I created a function to receive updates from Stripe webhook but I need the stripe-signature header to confirm the message belongs to Stripe

Lucas Reis
18 Jul, 2023, 04:15

mmm

Lucas Reis
18 Jul, 2023, 04:16

guess I gonna need to attach it to the body in the proxy layer then

Drake
18 Jul, 2023, 04:20

Yes. Here's one that does that: https://github.com/BoolCode/appwrite-funcover

Lucas Reis
18 Jul, 2023, 04:25

yeah, I just saw yours after creating mine XD https://github.com/ssa-web-solutions/appwrite-functions-proxy Not as professional as yours but works (it's lacking an auth layer though)

Drake
18 Jul, 2023, 04:27

This isn't mine btw. It's made by byawitz. Mine isn't as good 😅

Lucas Reis
18 Jul, 2023, 04:27

XD

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