mirror of
https://github.com/hex248/sprint.git
synced 2026-02-09 02:33:02 +00:00
use ServerQueryInput properly
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user