Skip to content

Commit

Permalink
Merge branch 'v3-main' of github.com:guildxyz/guild.xyz into add-guil…
Browse files Browse the repository at this point in the history
…d-page
  • Loading branch information
dominik-stumpf committed Dec 2, 2024
2 parents 6358a52 + bf4e8ff commit 811c65e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@storybook/react": "^8.4.4",
"@storybook/test": "^8.4.4",
"@svgr/webpack": "^8.1.0",
"@total-typescript/ts-reset": "^0.6.1",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
9 changes: 9 additions & 0 deletions query.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import '@tanstack/react-query'
import { ErrorLike } from './src/lib/types'

declare module '@tanstack/react-query' {
interface Register {
defaultError: ErrorLike
}
}

2 changes: 2 additions & 0 deletions reset.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Do not add any other lines of code to this file!
import "@total-typescript/ts-reset";
8 changes: 2 additions & 6 deletions src/app/(dashboard)/explorer/fetchers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { env } from "@/lib/env";
import type { Guild } from "@/lib/schemas/guild";
import type { PaginatedResponse } from "@/lib/types";
import { fetcher } from "../../../lib/fetcher";
import { PAGE_SIZE } from "./constants";

export const getGuildSearch =
(search = "") =>
async ({ pageParam }: { pageParam: number }) => {
const res = await fetch(
return fetcher<PaginatedResponse<Guild>>(
`${env.NEXT_PUBLIC_API}/guild/search?page=${pageParam}&pageSize=${PAGE_SIZE}&search=${search}`,
);
const json = await res.json();

if (json.error) throw new Error(json.error);

return json as PaginatedResponse<Guild>;
};
5 changes: 3 additions & 2 deletions src/lib/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { env } from "./env";
import type { ErrorLike } from "./types";

export const fetcher = async <Data = unknown, Error = unknown>(
resource: string,
Expand All @@ -13,8 +14,8 @@ export const fetcher = async <Data = unknown, Error = unknown>(
if (!response.ok) {
if (resource.includes(env.NEXT_PUBLIC_API)) {
return Promise.reject({
error: res.error,
} as { error: string });
error: (res as ErrorLike).error || (res as ErrorLike).message,
});
}

return Promise.reject(res as Error);
Expand Down
13 changes: 13 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ export type PaginatedResponse<Item = unknown> = {
export type DynamicRoute<T extends Record<string, string>> = {
params: T;
};

/**
* Unstable error structure coming from v3 backend
*
* @property message most common error response
* @property error on some endpoints this field is given instead of message
*/
// TODO: align this to backend when error handling gets consistent
export type ErrorLike = {
message: string;
status?: string;
error?: string;
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"next-env.d.ts",
"tailwind.config.ts",
".next/types/**/*.ts",
"guild.d.ts"
"reset.d.ts",
"query.d.ts"
],
"exclude": [
"node_modules",
Expand Down

0 comments on commit 811c65e

Please sign in to comment.