handle errors really well for the thing

This commit is contained in:
Nate Kelley 2025-03-27 17:07:22 -06:00
parent 94353c64e9
commit 7b2190cea9
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 7 additions and 13 deletions

View File

@ -34,4 +34,5 @@ export const rustErrorHandler = (errors: any = {}): RustApiError => {
export interface RustApiError { export interface RustApiError {
message?: string; message?: string;
status?: number;
} }

View File

@ -4,6 +4,7 @@ import { BASE_URL } from './buster_rest/config';
import type { RequestInit } from 'next/dist/server/web/spec-extension/request'; import type { RequestInit } from 'next/dist/server/web/spec-extension/request';
import { createClient } from '@/lib/supabase/server'; import { createClient } from '@/lib/supabase/server';
import { cookies } from 'next/headers'; import { cookies } from 'next/headers';
import { RustApiError } from './buster_rest/errors';
export interface FetchConfig extends RequestInit { export interface FetchConfig extends RequestInit {
baseURL?: string; baseURL?: string;
@ -40,11 +41,10 @@ export const serverFetch = async <T>(url: string, config: FetchConfig = {}): Pro
}); });
if (!response.ok) { if (!response.ok) {
const errorCode = response.status; throw {
const errorMessage = response.statusText; status: response.status,
throw new Error(`HTTP error! ${errorMessage}`, { message: response.statusText
cause: errorMessage } satisfies RustApiError;
});
} }
return response.json(); return response.json();

View File

@ -12,14 +12,7 @@ export default async function Page(props: {
const queryClient = await prefetchGetMetric({ id: metricId }); const queryClient = await prefetchGetMetric({ id: metricId });
const data = queryClient.getQueryData(queryKeys.metricsGetMetric(metricId).queryKey); // const state = queryClient.getQueryState(queryKeys.metricsGetMetric(metricId).queryKey);
const state = queryClient.getQueryState(queryKeys.metricsGetMetric(metricId).queryKey);
const errorMessage = state?.error?.message;
const errorCode = state?.error;
console.log('data-------', data);
console.log('state error message-------', errorMessage);
console.log('state error code-------', errorCode);
return ( return (
<HydrationBoundary state={dehydrate(queryClient)}> <HydrationBoundary state={dehydrate(queryClient)}>