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

View File

@ -12,14 +12,7 @@ export default async function Page(props: {
const queryClient = await prefetchGetMetric({ id: metricId });
const data = queryClient.getQueryData(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);
// const state = queryClient.getQueryState(queryKeys.metricsGetMetric(metricId).queryKey);
return (
<HydrationBoundary state={dehydrate(queryClient)}>