mirror of
https://git.srhtnin.garden/sarah/srhtnin.github.io.git
synced 2026-10-14 10:48:12 +02:00
51 lines
894 B
JavaScript
51 lines
894 B
JavaScript
let Plants = {};
|
|
|
|
|
|
async function FetchPlantsFromApi() {
|
|
const Response =
|
|
await fetch(
|
|
ApiUrl + "/Plants.php",
|
|
{
|
|
method: "GET",
|
|
|
|
headers: {
|
|
"Accept":
|
|
"application/json"
|
|
},
|
|
|
|
cache: "no-store"
|
|
}
|
|
);
|
|
|
|
|
|
if (!Response.ok) {
|
|
throw new Error(
|
|
"Plants API returned HTTP " +
|
|
Response.status
|
|
);
|
|
}
|
|
|
|
|
|
const Result =
|
|
await Response.json();
|
|
|
|
|
|
if (
|
|
!Result.Success ||
|
|
Result.Plants === null ||
|
|
typeof Result.Plants !==
|
|
"object" ||
|
|
Array.isArray(
|
|
Result.Plants
|
|
)
|
|
) {
|
|
throw new Error(
|
|
Result.Error ??
|
|
"Plants API returned invalid data."
|
|
);
|
|
}
|
|
|
|
|
|
return Result.Plants;
|
|
}
|