Display the day and improve error handling message
This commit is contained in:
parent
91b1492448
commit
58c769de55
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi";
|
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) {
|
function getAllFoods(data) {
|
||||||
// get the list of days and sort them by date ascending (the api for some reason sorts by weekday)
|
// 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 = [];
|
const foods = [];
|
||||||
days.map((day) => {
|
days.map((day) => {
|
||||||
foods.push(String(day.date));
|
foods.push(`${weekday[day.weekday]}, ${String(day.date)}`);
|
||||||
day.mealoptions.map((mealoption, index) => {
|
day.mealoptions.map((mealoption, index) => {
|
||||||
let str = ""
|
let str = ""
|
||||||
str += mealoption.name + ": "
|
str += mealoption.name + ": "
|
||||||
|
@ -30,4 +30,4 @@ function getAllFoods(data) {
|
||||||
fetch(APIURI)
|
fetch(APIURI)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => getAllFoods(data).map(food => console.log(food)))
|
.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)"));
|
||||||
|
|
Loading…
Reference in New Issue