standardize mobile api response parsing with shared helper

This commit is contained in:
dimitar committed 2026-03-29 15:48:58 +02:00
1 parent b1f84722af
commit ff9f3d582a
5 files changed
+43 -90

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import { ApiError, handleResponse } from "./responses";
import { type ApiResponse } from "./types";
export function parseApiData<T>(payload: unknown): T {
if (Array.isArray(payload)) {
return payload as T;
}
if (payload && typeof payload === "object" && "success" in payload) {
return handleResponse(payload as ApiResponse<T>);
}
throw new ApiError("Invalid response format");
}