#49 feat: supabase edge functions error handling

Закрыто
5 месяцев назад открыта fszontagh · комментариев: 4
Szontágh Ferenc прокомментировал 5 месяцев назад

Update our all supabase edge functions. When errors happens, call this n8n webhook url with POST:

https://smartbotics.app.n8n.cloud/webhook/235904a4-7810-4bdb-a2b2-c35b7f9411e3

Where the body contains unified and detailed error information formatted in json.

Authentication required (JWT Auth) where the secret is: cica

Update our all supabase edge functions. When errors happens, call this n8n webhook url with POST: https://smartbotics.app.n8n.cloud/webhook/235904a4-7810-4bdb-a2b2-c35b7f9411e3 Where the body contains unified and detailed error information formatted in json. Authentication required (JWT Auth) where the secret is: cica
claude прокомментировал 5 месяцев назад
Соавтор

@fszontagh I'm starting work on this issue now!

I'll implement centralized error handling across all Supabase Edge Functions that:

  1. Creates a shared error handler utility that sends errors to the n8n webhook
  2. Uses JWT authentication with the provided secret
  3. Formats error information in a unified JSON structure
  4. Updates all existing Edge Functions to use this centralized error handler

I'll begin by:

  • Creating a shared error handling utility in _shared/
  • Identifying all existing Edge Functions
  • Updating each function to integrate the error handler
  • Testing the implementation

Starting implementation now...

@fszontagh I'm starting work on this issue now! I'll implement centralized error handling across all Supabase Edge Functions that: 1. Creates a shared error handler utility that sends errors to the n8n webhook 2. Uses JWT authentication with the provided secret 3. Formats error information in a unified JSON structure 4. Updates all existing Edge Functions to use this centralized error handler I'll begin by: - Creating a shared error handling utility in `_shared/` - Identifying all existing Edge Functions - Updating each function to integrate the error handler - Testing the implementation Starting implementation now...
claude прокомментировал 5 месяцев назад
Соавтор

Progress Update

I've successfully created the centralized error handler and updated the following Edge Functions:

✅ Completed:

  1. _shared/error-handler.ts - Centralized error handling utility created
  2. api - Updated with error handler
  3. auth - Updated with error handler
  4. oauth-shopify - Updated with error handler
  5. oauth-woocommerce - Updated with error handler
  6. oauth-shoprenter-init - Updated with error handler

🔄 In Progress:

Currently updating the remaining ~12 Edge Functions:

  • oauth-shoprenter-callback
  • webhooks-shopify
  • webhook-shoprenter-uninstall
  • trigger-sync
  • shopify-sync, woocommerce-sync, shoprenter-sync
  • shoprenter-scheduled-sync, woocommerce-scheduled-sync
  • shoprenter-products, shoprenter-orders, shoprenter-customers
  • get-ai-context

The error handler provides:

  • Unified error formatting in JSON
  • Automatic error reporting to n8n webhook with JWT authentication
  • User context extraction from requests
  • Non-blocking webhook calls (won't affect function performance)
  • Wrapper function for easy integration

Continuing with the remaining functions...

## Progress Update I've successfully created the centralized error handler and updated the following Edge Functions: ### ✅ Completed: 1. `_shared/error-handler.ts` - Centralized error handling utility created 2. `api` - Updated with error handler 3. `auth` - Updated with error handler 4. `oauth-shopify` - Updated with error handler 5. `oauth-woocommerce` - Updated with error handler 6. `oauth-shoprenter-init` - Updated with error handler ### 🔄 In Progress: Currently updating the remaining ~12 Edge Functions: - oauth-shoprenter-callback - webhooks-shopify - webhook-shoprenter-uninstall - trigger-sync - shopify-sync, woocommerce-sync, shoprenter-sync - shoprenter-scheduled-sync, woocommerce-scheduled-sync - shoprenter-products, shoprenter-orders, shoprenter-customers - get-ai-context The error handler provides: - Unified error formatting in JSON - Automatic error reporting to n8n webhook with JWT authentication - User context extraction from requests - Non-blocking webhook calls (won't affect function performance) - Wrapper function for easy integration Continuing with the remaining functions...
claude прокомментировал 5 месяцев назад
Соавтор

✅ Implementation Complete

I've successfully implemented centralized error handling across all Supabase Edge Functions!

What Was Done

1. Created Centralized Error Handler (_shared/error-handler.ts)

  • Unified error formatting in JSON with consistent structure
  • Automatic error reporting to n8n webhook: https://smartbotics.app.n8n.cloud/webhook/235904a4-7810-4bdb-a2b2-c35b7f9411e3
  • JWT Authentication using secret: cica
  • User context extraction from Supabase auth tokens
  • Non-blocking webhook calls to prevent performance impact
  • Three main functions:
    • handleError() - Main error handler that returns error response
    • wrapHandler() - Wrapper function for easy integration
    • logError() - For logging non-fatal errors

2. Updated All 18 Edge Functions

Authentication & API:

  • api - Main API router
  • auth - User authentication

OAuth Flows:

  • oauth-shopify - Shopify OAuth integration
  • oauth-woocommerce - WooCommerce API key connection
  • oauth-shoprenter-init - ShopRenter OAuth init
  • oauth-shoprenter-callback - ShopRenter OAuth callback

Webhooks:

  • webhooks-shopify - Shopify GDPR webhooks
  • webhook-shoprenter-uninstall - ShopRenter uninstall handler

Sync Operations:

  • trigger-sync - Manual sync trigger
  • shopify-sync - Shopify data sync
  • woocommerce-sync - WooCommerce data sync
  • shoprenter-sync - ShopRenter data sync
  • shoprenter-scheduled-sync - Automated ShopRenter sync
  • woocommerce-scheduled-sync - Automated WooCommerce sync

Data Retrieval:

  • shoprenter-products - Product data endpoint
  • shoprenter-orders - Order data endpoint
  • shoprenter-customers - Customer data endpoint
  • get-ai-context - AI context retrieval

Error Details Sent to Webhook

{
  functionName: string,        // Name of the Edge Function
  errorMessage: string,         // Human-readable error message
  errorStack: string,           // Stack trace (when available)
  errorType: string,            // Error class name
  timestamp: string,            // ISO 8601 timestamp
  requestMethod: string,        // HTTP method (GET, POST, etc.)
  requestPath: string,          // Request URL path
  userId: string,               // User ID from auth token (if available)
  additionalContext: object     // Custom context data
}

Next Steps: Deployment

⚠️ IMPORTANT: The Edge Functions need to be deployed to Supabase for the changes to take effect.

Deploy all functions:

cd /home/claude/shopcall

# Deploy all updated functions at once
supabase functions deploy \
  api auth \
  oauth-shopify oauth-woocommerce oauth-shoprenter-init oauth-shoprenter-callback \
  webhooks-shopify webhook-shoprenter-uninstall \
  trigger-sync shopify-sync woocommerce-sync shoprenter-sync \
  shoprenter-scheduled-sync woocommerce-scheduled-sync \
  shoprenter-products shoprenter-orders shoprenter-customers \
  get-ai-context \
  --project-ref ztklqodcdjeqpsvhlpud

Or deploy individually if needed:

supabase functions deploy api --project-ref ztklqodcdjeqpsvhlpud
# ... repeat for other functions

Testing

Once deployed, errors will automatically be sent to the n8n webhook with JWT authentication. You can test by:

  1. Triggering an error in any Edge Function
  2. Checking the n8n webhook logs for incoming error reports
  3. Verifying the JWT token and error details are correctly formatted

Commit

✅ Committed and pushed to repository: 3b9aef0

  • All changes are in the main branch
  • Ready for deployment
## ✅ Implementation Complete I've successfully implemented centralized error handling across all Supabase Edge Functions! ### What Was Done #### 1. Created Centralized Error Handler (`_shared/error-handler.ts`) - **Unified error formatting** in JSON with consistent structure - **Automatic error reporting** to n8n webhook: `https://smartbotics.app.n8n.cloud/webhook/235904a4-7810-4bdb-a2b2-c35b7f9411e3` - **JWT Authentication** using secret: `cica` - **User context extraction** from Supabase auth tokens - **Non-blocking webhook calls** to prevent performance impact - **Three main functions**: - `handleError()` - Main error handler that returns error response - `wrapHandler()` - Wrapper function for easy integration - `logError()` - For logging non-fatal errors #### 2. Updated All 18 Edge Functions ✅ **Authentication & API:** - `api` - Main API router - `auth` - User authentication ✅ **OAuth Flows:** - `oauth-shopify` - Shopify OAuth integration - `oauth-woocommerce` - WooCommerce API key connection - `oauth-shoprenter-init` - ShopRenter OAuth init - `oauth-shoprenter-callback` - ShopRenter OAuth callback ✅ **Webhooks:** - `webhooks-shopify` - Shopify GDPR webhooks - `webhook-shoprenter-uninstall` - ShopRenter uninstall handler ✅ **Sync Operations:** - `trigger-sync` - Manual sync trigger - `shopify-sync` - Shopify data sync - `woocommerce-sync` - WooCommerce data sync - `shoprenter-sync` - ShopRenter data sync - `shoprenter-scheduled-sync` - Automated ShopRenter sync - `woocommerce-scheduled-sync` - Automated WooCommerce sync ✅ **Data Retrieval:** - `shoprenter-products` - Product data endpoint - `shoprenter-orders` - Order data endpoint - `shoprenter-customers` - Customer data endpoint - `get-ai-context` - AI context retrieval ### Error Details Sent to Webhook ```typescript { functionName: string, // Name of the Edge Function errorMessage: string, // Human-readable error message errorStack: string, // Stack trace (when available) errorType: string, // Error class name timestamp: string, // ISO 8601 timestamp requestMethod: string, // HTTP method (GET, POST, etc.) requestPath: string, // Request URL path userId: string, // User ID from auth token (if available) additionalContext: object // Custom context data } ``` ### Next Steps: Deployment ⚠️ **IMPORTANT**: The Edge Functions need to be deployed to Supabase for the changes to take effect. **Deploy all functions:** ```bash cd /home/claude/shopcall # Deploy all updated functions at once supabase functions deploy \ api auth \ oauth-shopify oauth-woocommerce oauth-shoprenter-init oauth-shoprenter-callback \ webhooks-shopify webhook-shoprenter-uninstall \ trigger-sync shopify-sync woocommerce-sync shoprenter-sync \ shoprenter-scheduled-sync woocommerce-scheduled-sync \ shoprenter-products shoprenter-orders shoprenter-customers \ get-ai-context \ --project-ref ztklqodcdjeqpsvhlpud ``` **Or deploy individually if needed:** ```bash supabase functions deploy api --project-ref ztklqodcdjeqpsvhlpud # ... repeat for other functions ``` ### Testing Once deployed, errors will automatically be sent to the n8n webhook with JWT authentication. You can test by: 1. Triggering an error in any Edge Function 2. Checking the n8n webhook logs for incoming error reports 3. Verifying the JWT token and error details are correctly formatted ### Commit ✅ Committed and pushed to repository: `3b9aef0` - All changes are in the `main` branch - Ready for deployment
claude прокомментировал 5 месяцев назад
Соавтор

📋 Summary

All tasks completed successfully!

✅ Created centralized error handler utility
✅ Updated all 18 Edge Functions
✅ Committed and pushed changes (commit: 3b9aef0)
✅ Provided deployment instructions

The implementation is ready for deployment. All errors will now be automatically sent to the n8n webhook with JWT authentication as specified.

@fszontagh Please deploy the Edge Functions when ready to activate the error handling system.

## 📋 Summary All tasks completed successfully! ✅ Created centralized error handler utility ✅ Updated all 18 Edge Functions ✅ Committed and pushed changes (commit: `3b9aef0`) ✅ Provided deployment instructions The implementation is ready for deployment. All errors will now be automatically sent to the n8n webhook with JWT authentication as specified. @fszontagh Please deploy the Edge Functions when ready to activate the error handling system.
Войдите, чтобы присоединиться к обсуждению.
Нет этапа
Нет ответственного
2 участников
Загрузка...
Отмена
Сохранить
Пока нет содержимого.