Get localized error messages.
This commit is contained in:
@@ -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 = {}) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user