Exercise 2: The Concrete Advantage of a Structured detail Array — Possible Solution ==================================================================== WHAT THE EXPRESS SIBLING'S ERROR SHAPE PROVIDES ------------------------------ Food Tracker (React + Express) returns a single string, such as { "error": "name is required" }. A frontend receiving this knows something went wrong and can display that one message somewhere, but the response itself gives no structured way to know which specific form field the message refers to beyond parsing the English text of the message itself. WHAT FASTAPI'S detail ARRAY PROVIDES INSTEAD ------------------------------ Each entry in detail includes a loc array identifying exactly where the problem was found (for example ["body", "name"]), plus a msg describing what went wrong. This is structured, predictable data - the same shape regardless of which field failed or how many fields failed at once. WHAT showFieldErrors IS SPECIFICALLY ABLE TO DO WITH THIS ------------------------------ Because each error entry names its own field via loc, showFieldErrors can loop through every entry in detail and, for each one, look up the exact form element responsible (via a matching data-field-error attribute) and place that specific message right next to that specific input - even when multiple fields fail validation at once. Doing the equivalent with a single free-form string would require parsing English text to guess which field it referred to, which is fragile and doesn't reliably generalize to multiple simultaneous errors. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly contrasts the single-string error shape against the structured array, and correctly explains the concrete capability the structure enables - accurately routing potentially multiple distinct error messages to their own specific form fields, rather than only ever having one generic message to show somewhere.