Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update quickstart.mdx

Ayushh Khare7e0e414eff30
diff --git a/apps/docs/pages/guides/functions/quickstart.mdx b/apps/docs/pages/guides/functions/quickstart.mdx
index 7c32c36db06..9c77be26d04 100644
--- a/apps/docs/pages/guides/functions/quickstart.mdx
+++ b/apps/docs/pages/guides/functions/quickstart.mdx
@@ -106,6 +106,33 @@ const { data, error } = await supabase.functions.invoke('hello-world', {
After invoking your Edge Function you should see the response `{ "message":"Hello Functions!" }`.
+### Error Handling
+
+When interacting with Edge Functions, it's important to be prepared for potential errors that might occur during the invocation. To handle errors effectively, the following error handling code can be used:
+
+```js
+import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
+
+const { data, error } = await supabase.functions.invoke('hello', {
+ headers: {
+ "my-custom-header": 'my-custom-header-value'
+ },
+ body: { foo: 'bar' }
+})
+
+if (error instanceof FunctionsHttpError) {
+ const errorMessage = await error.context.json()
+ console.log('Function returned an error', errorMessage)
+} else if (error instanceof FunctionsRelayError) {
+ console.log('Relay error:', error.message)
+} else if (error instanceof FunctionsFetchError) {
+ console.log('Fetch error:', error.message)
+}
+```
+In the provided error handling code, we're checking the type of error that occurred using the "instanceof" operator. This helps us differentiate between different types of errors and handle them appropriately. Depending on the type of error, we either log the error message or information specific to that type of error.
+
+This error handling mechanism ensures that your application can gracefully handle errors that might arise during the execution of Edge Functions, providing a more robust user experience.
+
## Importing Node npm modules
We recommend using [esm.sh](https://esm.sh/) for importing Node.js modules that are published to npm. To do so you simply put `https://esm.sh/` in front of the package name.