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 {
|
||||
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 { 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();
|
||||
|
|
|
@ -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)}>
|
||||
|
|
Loading…
Reference in New Issue