use ServerQueryInput properly

This commit is contained in:
Oliver Bryan
2026-01-13 15:33:55 +00:00
parent 4e93eb5878
commit ca371b1751
21 changed files with 284 additions and 329 deletions

View File

@@ -8,7 +8,7 @@ export async function byUsername({
onError,
}: {
username: string;
} & ServerQueryInput) {
} & ServerQueryInput<UserRecord>) {
const url = new URL(`${getServerURL()}/user/by-username`);
url.searchParams.set("username", username);
@@ -17,8 +17,10 @@ export async function byUsername({
});
if (!res.ok) {
const error = await res.text();
onError?.(error || `failed to get user (${res.status})`);
const error = await res.json().catch(() => res.text());
const message =
typeof error === "string" ? error : error.error || `failed to get user (${res.status})`;
onError?.(message);
} else {
const data = (await res.json()) as UserRecord;
onSuccess?.(data, res);