fix: debouncing sync and other improvements
This commit is contained in:
+2
-10
@@ -1,15 +1,7 @@
|
||||
import type { LoginPayload, RefreshPayload, TokenPair } from '@/types/auth'
|
||||
import { API_BASE_URL, extractErrorMessage } from '@/api/http'
|
||||
|
||||
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? '/api/v1'
|
||||
|
||||
async function extractErrorMessage(response: Response, fallback: string): Promise<string> {
|
||||
try {
|
||||
const errorData = await response.json()
|
||||
return errorData.message || errorData.error || fallback
|
||||
} catch {
|
||||
return response.statusText || fallback
|
||||
}
|
||||
}
|
||||
export { API_BASE_URL }
|
||||
|
||||
async function postJson(
|
||||
path: string,
|
||||
|
||||
+9
-3
@@ -1,6 +1,8 @@
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { API_BASE_URL } from '@/api/auth'
|
||||
import router from '@/router'
|
||||
import { API_BASE_URL, extractErrorMessage } from '@/api/http'
|
||||
|
||||
export { API_BASE_URL, extractErrorMessage }
|
||||
|
||||
let refreshPromise: Promise<unknown> | null = null
|
||||
|
||||
@@ -94,6 +96,10 @@ export const apiClient = {
|
||||
method: 'PUT',
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
}),
|
||||
delete: (endpoint: string, options?: FetchOptions) =>
|
||||
fetchWithAuth(endpoint, { ...options, method: 'DELETE' }),
|
||||
delete: (endpoint: string, body?: unknown, options?: FetchOptions) =>
|
||||
fetchWithAuth(endpoint, {
|
||||
...options,
|
||||
method: 'DELETE',
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? '/api/v1'
|
||||
|
||||
export async function extractErrorMessage(response: Response, fallback: string): Promise<string> {
|
||||
try {
|
||||
const errorData = await response.json()
|
||||
return errorData.message || errorData.error || fallback
|
||||
} catch {
|
||||
return response.statusText || fallback
|
||||
}
|
||||
}
|
||||
+2
-12
@@ -1,4 +1,5 @@
|
||||
import { apiClient } from '@/api/client'
|
||||
import { extractErrorMessage } from '@/api/http'
|
||||
import type {
|
||||
List,
|
||||
ListItem,
|
||||
@@ -10,15 +11,6 @@ import type {
|
||||
RemoveUserFromListPayload,
|
||||
} from '@/types/list'
|
||||
|
||||
async function extractErrorMessage(response: Response, fallback: string): Promise<string> {
|
||||
try {
|
||||
const errorData = await response.json()
|
||||
return errorData.message || errorData.error || fallback
|
||||
} catch {
|
||||
return response.statusText || fallback
|
||||
}
|
||||
}
|
||||
|
||||
export async function getListsApi(): Promise<List[]> {
|
||||
const response = await apiClient.get('/lists')
|
||||
if (!response.ok) {
|
||||
@@ -76,9 +68,7 @@ export async function addUserToListApi(payload: AddUserToListPayload): Promise<v
|
||||
}
|
||||
|
||||
export async function removeUserFromListApi(payload: RemoveUserFromListPayload): Promise<void> {
|
||||
const response = await apiClient.delete('/lists/user', {
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
const response = await apiClient.delete('/lists/user', payload)
|
||||
if (!response.ok) {
|
||||
throw new Error(await extractErrorMessage(response, 'Failed to remove user from list'))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user