Display the day and improve error handling message

This commit is contained in:
Your Name 2022-11-21 09:43:28 +02:00
parent 91b1492448
commit 58c769de55
1 changed files with 3 additions and 3 deletions

View File

@ -2,7 +2,7 @@
import fetch from "node-fetch";
const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi";
const myArgs = process.argv.slice(2);
const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
function getAllFoods(data) {
// get the list of days and sort them by date ascending (the api for some reason sorts by weekday)
@ -12,7 +12,7 @@ function getAllFoods(data) {
const foods = [];
days.map((day) => {
foods.push(String(day.date));
foods.push(`${weekday[day.weekday]}, ${String(day.date)}`);
day.mealoptions.map((mealoption, index) => {
let str = ""
str += mealoption.name + ": "
@ -30,4 +30,4 @@ function getAllFoods(data) {
fetch(APIURI)
.then(response => response.json())
.then(data => getAllFoods(data).map(food => console.log(food)))
.catch(err => console.error("Error when fetching resource (api endpoint might be down)"));
.catch(() => console.error("Error when fetching resource (api endpoint might be down)"));