supabase-community/functions-swift

Invoking function always results in a `unacceptableStatusCode(404)` return

matthewmorek opened this issue · 1 comments

Bug report

Describe the bug

When trying to invoke any Edge Function from supabase-swift client context (with or without invoke options) throws an error unacceptableStatusCode(404). Call does not register in the Edge Functions log browser, but it appears in the API Edge Network log browser as a 404 (see below) using a different invocation URL format:

functions-swift

https://xxx.supabase.co/functions/v1/preview-issue

Edge Functions API documentation

https://xxx.functions.supabase.co/preview-issue

The function name is correct (preview-issue) and can be accessed using Edge Functions API, so it appears that the invocation URL for functions-swift uses an incorrect format.

To Reproduce

Invoke a Edge Function using the following signature (after setting up your Supabase Swift client:

do {
    try await client.functions.invoke(functionName: "preview-issue", invokeOptions: .init(headers: ["param": "some-string"]))
} catch {
    throw error
}

Expected behavior

  • Invocation succeeds and the Edge Function result returns expected response
  • Invocation gets registered in the Edge Functions log browser

Logs

Log ID
4edd9ee6-9cff-47c3-a476-8426515f3ad2

Log Timestamp (UTC)
2023-02-12T12:24:31.132Z

Log Event Message
POST | 404 | 213.205.242.39 | 79854d3a4d27777a | https://xxx.supabase.co/functions/v1/preview-issue

Log Metadata
[
  {
    "request": [
      {
        "headers": [
          {
            "accept": "application/json",
            "cf_cache_status": null,
            "cf_connecting_ip": "213.205.242.39",
            "cf_ipcountry": "GB",
            "cf_ray": "79854d3a4d27777a",
            "content_length": "0",
            "content_location": null,
            "content_range": null,
            "content_type": null,
            "date": null,
            "host": "xxx.supabase.co",
            "referer": null,
            "sb_gateway_version": null,
            "user_agent": "iOS/1 CFNetwork/1402.0.8 Darwin/22.3.0",
            "x_client_info": "functions-swift/0.2.0",
            "x_forwarded_proto": "https",
            "x_forwarded_user_agent": null,
            "x_kong_proxy_latency": null,
            "x_kong_upstream_latency": null,
            "x_real_ip": "213.205.242.39"
          }
        ],
        "host": "xxx.supabase.co",
        "method": "POST",
        "path": "/functions/v1/preview-issue",
        "port": null,
        "protocol": "https:",
        "sb": [],
        "search": null,
        "url": "https://xxx.supabase.co/functions/v1/preview-issue"
      }
    ],
    "response": [
      {
        "headers": [
          {
            "cf_cache_status": "DYNAMIC",
            "cf_ray": "79854d3a7723777a-LHR",
            "content_length": "48",
            "content_location": null,
            "content_range": null,
            "content_type": "application/json; charset=utf-8",
            "date": "Sun, 12 Feb 2023 12:24:31 GMT",
            "sb_gateway_mode": null,
            "sb_gateway_version": "1",
            "transfer_encoding": null,
            "x_kong_proxy_latency": null,
            "x_kong_upstream_latency": null
          }
        ],
        "origin_time": 37,
        "status_code": 404
      }
    ]
  }
]

System information

  • OS: iOS 16.1
  • Swift: 5.7
  • Xcode: 14.2
  • supabase-swift: 0.1.2
  • functions-swift: 0.2.0

Looks like this issue needs to be moved to supabase-swift repo, since functions-swift gets its set up URL from that master package, see here: https://github.com/supabase-community/supabase-swift/blob/8292bf9a8eb21ca1bcfbd249ed84e67776e5ee2f/Sources/Supabase/SupabaseClient.swift#L49