INNER CODE UNIT · JavaScript
opsHref
rootSunc/CNEquity · frontend/src/main.js:98
function opsHref(op, params) {
const query = new URLSearchParams();
query.set("op", op);
for (const [key, value] of Object.entries(params || {})) {
if (Array.isArray(value)) query.set(key, value.join(","));
else if (value != null && value !== "") query.set(key, String(value));
}
return `#/ops?${query}`;
}
async function api(path, options) {
const sep = path.includes("?") ? "&" : "?";
const url = TOKEN ? `${path}${sep}token=${encodeURIComponent(TOKEN)}` : path;
const res = await fetch(url, options);
if (!res.ok) {
// Surface what the server said. A 422 here is usually a real contract
// message ("requires as_of= for point-in-time queries"), and showing the
// status code instead throws away the one useful part.