Fix RQ error handling for views query (#21252)

This commit is contained in:
Joshen Lim authored and GitHub committed 2024-02-15 17:38:37 +08:00
1 parent 7f084ce27b
commit c915042250
5 files changed
+20 -22

No files matched your search

@@ -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
}
@@ -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
}
@@ -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
}
+16 -17
View File
@@ -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,
+1 -1
View File
@@ -32,7 +32,7 @@ export async function getViews(
signal,
})
if (error) throw error
if (error) throw new Error((error as ResponseError).message)
return data
}