Get localized error messages.

This commit is contained in:
Mike Cao 2025-09-14 23:43:22 -07:00
parent baba06c692
commit fc01ee9f56
32 changed files with 90 additions and 85 deletions

View file

@ -1,4 +1,4 @@
import { buildUrl } from '@/lib/url';
import { buildPath } from '@/lib/url';
export interface ErrorResponse {
error: {
@ -36,18 +36,17 @@ export async function request(
return {
ok: res.ok,
status: res.status,
data: res.ok ? data : undefined,
error: res.ok ? undefined : data,
data,
};
});
}
export async function httpGet(path: string, params: object = {}, headers: object = {}) {
return request('GET', buildUrl(path, params), undefined, headers);
return request('GET', buildPath(path, params), undefined, headers);
}
export async function httpDelete(path: string, params: object = {}, headers: object = {}) {
return request('DELETE', buildUrl(path, params), undefined, headers);
return request('DELETE', buildPath(path, params), undefined, headers);
}
export async function httpPost(path: string, params: object = {}, headers: object = {}) {

View file

@ -10,9 +10,9 @@ export function getQueryString(params: object = {}): string {
return searchParams.toString();
}
export function buildUrl(url: string, params: object = {}): string {
export function buildPath(path: string, params: object = {}): string {
const queryString = getQueryString(params);
return `${url}${queryString && '?' + queryString}`;
return queryString ? `${path}?${queryString}` : path;
}
export function safeDecodeURI(s: string | undefined | null): string | undefined | null {