Make restricted app use simple fetch that doesn't do API authentication (recursively).

This commit is contained in:
Leo Vasanko
2025-12-03 18:20:14 -06:00
parent 7c82727d28
commit d541377798
2 changed files with 34 additions and 4 deletions
+30
View File
@@ -280,6 +280,36 @@ export async function apiJson(url, options = {}) {
return data
}
/**
* Simple JSON fetch without auto-auth iframe handling.
* Use this in contexts where showing an auth iframe would be inappropriate
* (e.g., inside the auth iframe itself).
*
* @param {string|URL} url - The URL to fetch
* @param {RequestInit} [options] - Fetch options
* @returns {Promise<any>} - Parsed JSON response
* @throws {ApiError} - If response is not ok
*/
export async function fetchJson(url, options = {}) {
const fetchOptions = {
credentials: 'include',
...options,
headers: {
'Accept': 'application/json',
...options.headers,
},
}
const response = await fetch(url, fetchOptions)
const data = await response.json()
if (!response.ok) {
throw new ApiError(url, response, data)
}
return data
}
/**
* Convert an error to a user-friendly message.
* @param {Error} error - The error to convert