diff --git a/studio/data/api-authorization/api-authorization-query.ts b/studio/data/api-authorization/api-authorization-query.ts index bf73ad67872..652c19c4d5f 100644 --- a/studio/data/api-authorization/api-authorization-query.ts +++ b/studio/data/api-authorization/api-authorization-query.ts @@ -24,29 +24,12 @@ export async function getApiAuthorizationDetails( if (!id) throw new Error('Authorization ID is required') const response = await get(`${API_ADMIN_URL}/oauth/authorizations/${id}`, { signal }) - if (response.error) { - // 404 is a valid error in which the auth id is invalid - const isInvalid = - (response.error as any)?.code === 404 && - (response.error as any)?.message?.includes('OAuth authorization request does not exist') - - if (isInvalid) { - return { - name: '', - website: '', - domain: '', - expires_at: '', - approved_at: null, - } as ApiAuthorizationResponse - } - - throw response.error - } + if (response.error) throw response.error return response as ApiAuthorizationResponse } export type ResourceData = Awaited> -export type ResourceError = unknown +export type ResourceError = { errorEventId: string; message: string } export const useApiAuthorizationQuery = ( { id }: ApiAuthorizationVariables, diff --git a/studio/pages/authorize.tsx b/studio/pages/authorize.tsx index 5ea6e61ae0a..86559bebe6e 100644 --- a/studio/pages/authorize.tsx +++ b/studio/pages/authorize.tsx @@ -24,9 +24,8 @@ const APIAuthorizationPage: NextPageWithLayout = () => { const [selectedOrg, setSelectedOrg] = useState() const { data: organizations, isLoading: isLoadingOrganizations } = useOrganizationsQuery() - const { data: requester, isLoading, isError } = useApiAuthorizationQuery({ id: auth_id }) + const { data: requester, isLoading, isError, error } = useApiAuthorizationQuery({ id: auth_id }) const isApproved = requester?.approved_at !== null - const isInvalid = requester?.name.length === 0 && requester.expires_at.length === 0 const isExpired = dayjs().isAfter(dayjs(requester?.expires_at)) const { mutateAsync: approveRequest } = useApiAuthorizationApproveMutation() @@ -75,6 +74,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => { try { setIsSubmitting(true) await declineRequest({ id: auth_id }) + ui.setNotification({ category: 'success', message: 'Declined API authorization request' }) router.push('/projects') } catch (error: any) { ui.setNotification({ @@ -109,7 +109,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => { ) } - if (isInvalid || isError) { + if (isError) { return ( Authorize API access

}>
@@ -118,7 +118,8 @@ const APIAuthorizationPage: NextPageWithLayout = () => { variant="warning" title="Failed to fetch details for API authorization request" > - Please retry your authorization request from the requesting app +

Please retry your authorization request from the requesting app

+ {error !== undefined &&

Error: {error?.message}

}