Skip to content

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

Fix RQ error handling for views query (#21252)

Joshen Limc91504225046
diff --git a/apps/studio/data/__templates/resource-query.ts b/apps/studio/data/__templates/resource-query.ts
index 25889a82fd0..08a72400c23 100644
--- a/apps/studio/data/__templates/resource-query.ts
+++ b/apps/studio/data/__templates/resource-query.ts
@@ -22,7 +22,7 @@ export async function getResource({ projectRef, id }: ResourceVariables, signal?
params: { path: { ref: projectRef, id } },
signal,
})
- if (error) throw error
+ if (error) throw new Error((error as ResponseError).message)
return data
}
diff --git a/apps/studio/data/__templates/resource-update-mutation.ts b/apps/studio/data/__templates/resource-update-mutation.ts
index 150e99ff370..16310dcb978 100644
--- a/apps/studio/data/__templates/resource-update-mutation.ts
+++ b/apps/studio/data/__templates/resource-update-mutation.ts
@@ -18,7 +18,7 @@ export async function updateResource({ projectRef, id, updatedParam }: ResourceU
body: { updatedParam },
})
- if (error) throw error
+ if (error) throw new Error((error as ResponseError).message)
return data
}
diff --git a/apps/studio/data/__templates/resources-query.ts b/apps/studio/data/__templates/resources-query.ts
index 4167d032a1a..8545612ba7e 100644
--- a/apps/studio/data/__templates/resources-query.ts
+++ b/apps/studio/data/__templates/resources-query.ts
@@ -17,8 +17,7 @@ export async function getResources({ projectRef }: ResourcesVariables, signal?:
params: { path: { ref: projectRef } },
signal,
})
- if (error) throw error
-
+ if (error) throw new Error((error as ResponseError).message)
return data
}
diff --git a/apps/studio/data/views/view-query.ts b/apps/studio/data/views/view-query.ts
index fa4a597180b..b87ae24165b 100644
--- a/apps/studio/data/views/view-query.ts
+++ b/apps/studio/data/views/view-query.ts
@@ -1,7 +1,8 @@
import { PostgresView } from '@supabase/postgres-meta'
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
-import { get } from 'lib/common/fetch'
-import { API_URL } from 'lib/constants'
+
+import { get } from 'data/fetchers'
+import { ResponseError } from 'types'
import { viewKeys } from './keys'
export type ViewVariables = {
@@ -18,30 +19,28 @@ export async function getView(
{ id, projectRef, connectionString }: ViewVariables,
signal?: AbortSignal
) {
- if (!projectRef) {
- throw new Error('projectRef is required')
- }
- if (!id) {
- throw new Error('id is required')
- }
+ if (!projectRef) throw new Error('projectRef is required')
+ if (!id) throw new Error('id is required')
let headers = new Headers()
if (connectionString) headers.set('x-connection-encrypted', connectionString)
- const response = (await get(`${API_URL}/pg-meta/${projectRef}/views?id=${id}`, {
- headers: Object.fromEntries(headers),
+ const { data, error } = await get('/platform/pg-meta/{ref}/views', {
+ params: {
+ header: { 'x-connection-encrypted': connectionString! },
+ path: { ref: projectRef },
+ query: { id: `${id}` } as any,
+ },
+ headers,
signal,
- })) as ViewResponse
-
- if ('error' in response) {
- throw response.error
- }
+ })
- return response as PostgresView
+ if (error) throw new Error((error as ResponseError).message)
+ return data as unknown as PostgresView
}
export type ViewData = Awaited<ReturnType<typeof getView>>
-export type ViewError = unknown
+export type ViewError = ResponseError
export const useViewQuery = <TData = ViewData>(
{ projectRef, connectionString, id }: ViewVariables,
diff --git a/apps/studio/data/views/views-query.ts b/apps/studio/data/views/views-query.ts
index 38c83410b90..a367a3466a9 100644
--- a/apps/studio/data/views/views-query.ts
+++ b/apps/studio/data/views/views-query.ts
@@ -32,7 +32,7 @@ export async function getViews(
signal,
})
- if (error) throw error
+ if (error) throw new Error((error as ResponseError).message)
return data
}