The market from Lecture 5 still reads its vendors from js/data.js, typed by hand. The course server has the real list, with two more stalls and their ratings, and you have your own copy of it. Connect the two: every request through one module, the stalls in state, and a page that says what's happening while the data is on its way, or when it doesn't arrive.
“The website says eight stalls. The market has ten.”
Done means: localhost:8080 shows ten vendors with ratings, loaded with one GET …/api/stalls from your market. The course server fails about 1 request in 10 with a 500 on purpose, so the error path runs even without chaos. With chaos on (harbour-api.lopin.me), a reload shows "Loading the vendors…", a failed one shows a sentence and a Try again button that recovers, and the console has no Uncaught. data.js is deleted.
git switch -c connect-the-market.API at the top of starter/js/api.js.npm start (live-server, through npx; no npm install). Open http://localhost:8080: eight vendors, typed by hand.starter/.Each step says how you know it works. Check before moving on.
HttpError: name, a message with the status and the server's message, status and body on it.request(method, path, data, options): fetch(API + path, …); a JSON body and its Content-Type when there is data; on a non-2xx, read the error body (ignore it if it isn't JSON) and throw an HttpError; null for a 204; otherwise the parsed body.describe(error): a short sentence for people, from the error's status or name.const api = await import("/js/api.js"), then await api.getJSON("/stalls") gives 10 stalls and await api.getJSON("/stalls/pizza") rejects with an error whose status is 404.state gets status ("loading" · "ready" · "error"), error and stalls: []. visibleStalls() and render() read state.stalls.loadStalls() in main.js: loading, render, request, ready or error, render. Started with a top-level await.data.js: delete it.GET /api/stalls in the Network panel; the filters, the search and the ♥ still work.role="alert" element that stays in the page, and a Try again button that's hidden unless there's an error. Try again moves focus to the status line, then calls loadStalls().★ 4.7 · 3 reviews, or "no reviews yet".Uncaught.localStorage), the stalls arrive later.Network panel first: is the request sent, with what, and what came back? Then the console. Then a hint.
Which modules import stalls from data.js today, and what should each of them read instead?
render() runs before the stalls arrive. What should it draw when state.stalls is empty because they're still loading, and when it's empty because the market has no stalls?
Which of the four failure modes from slide "How a request fails" can loadStalls() meet, and which line of your code turns each one into state.status = "error"?
The error message and the Try again button: which of them must stay in the page all the time, and why?
The requested module './data.js' … or a 404 for data.js.Unexpected token '<', or a 404 for /api/api/stalls.Uncaught (in promise) in the console.API.localhost:8080/api/…: API is still a relative path.npm start, Network panel open.Push your branch to your fork and open a pull request against harbour-market-starter's main. In the description: what works, what doesn't yet, and how you tested it with chaos on. A PR that's still in progress is fine: mark it as a draft and finish it at home.
Pick one of the briefs: they all start from a connected market. A new branch on top of this one, a second pull request; start its core in class, finish at home, demo next class.