mirror of https://github.com/buster-so/buster.git
handle errors really well for the thing
This commit is contained in:
parent
94353c64e9
commit
7b2190cea9
|
@ -34,4 +34,5 @@ export const rustErrorHandler = (errors: any = {}): RustApiError => {
|
||||||
|
|
||||||
export interface RustApiError {
|
export interface RustApiError {
|
||||||
message?: string;
|
message?: string;
|
||||||
|
status?: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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)}>
|
||||||
|
|
Loading…
Reference in New Issue