✨ feat: implement mock data support with API interceptor and update documentation
This commit is contained in:
@@ -16,6 +16,7 @@ import { apiBaseOverride } from "./store"
|
||||
import { incrementRequests, decrementRequests } from "./requestsStore"
|
||||
import { setServerBuildTime } from "./serverBuildInfo"
|
||||
import { checkBuildVersion } from "./versionCheck"
|
||||
import { mockApiRequest } from "./mock"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Request deduplication
|
||||
@@ -84,6 +85,14 @@ export const api = async <T>(
|
||||
}
|
||||
incrementRequests()
|
||||
|
||||
// ── Mock interceptor (tree-shaken when __MOCK__ is false) ──
|
||||
if (__MOCK__) {
|
||||
const mockResult = mockApiRequest(endpoint, mergedOptions, body)
|
||||
if (mockResult) return mockResult as ApiResult<T>
|
||||
// No mock data for this endpoint → 404
|
||||
throw { response: { status: 404 }, data: { error: `[mock] No mock data for "${endpoint}"` } }
|
||||
}
|
||||
|
||||
const data = await apiRequest(_apiBaseOverride + endpoint, mergedOptions, body, sentry)
|
||||
|
||||
// Build-version check only on GETs (don't reload mid-write)
|
||||
|
||||
Reference in New Issue
Block a user