f4lco / om-parser-stw-potsdam-v2

Connect canteens of the Studentenwerk Potsdam to OpenMensa
3 stars 7 forks source link

Occasional cron build failure due to API instability #6

Open f4lco opened 6 years ago

f4lco commented 6 years ago

The build health is also determined by the cron build which tests for parseable API output once per day. However, the API is a little unstable and at times the JSON endpoint returns outputs of the following kind:

<style type='text/css'>
        .extbase-debugger-tree{position:relative}
        .extbase-debugger-tree input{position:absolute !important;float: none !important;top:0;left:0;height:14px;width:14px;margin:0 !important;cursor:pointer;opacity:0;z-index:2}
        .extbase-debugger-tree input~.extbase-debug-content{display:none}
        .extbase-debugger-tree .extbase-debug-header:before{position:relative;top:3px;content:"";padding:0;line-height:10px;height:12px;width:12px;text-align:center;margin:0 3px 0 0;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTIgMTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDEyIDEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6Izg4ODg4ODt9PC9zdHlsZT48cGF0aCBpZD0iQm9yZGVyIiBjbGFzcz0ic3QwIiBkPSJNMTEsMTFIMFYwaDExVjExeiBNMTAsMUgxdjloOVYxeiIvPjxnIGlkPSJJbm5lciI+PHJlY3QgeD0iMiIgeT0iNSIgY2xhc3M9InN0MCIgd2lkdGg9IjciIGhlaWdodD0iMSIvPjxyZWN0IHg9IjUiIHk9IjIiIGNsYXNzPSJzdDAiIHdpZHRoPSIxIiBoZWlnaHQ9IjciLz48L2c+PC9zdmc+);display:inline-block}
        .extbase-debugger-tree input:checked~.extbase-debug-content{display:inline}
        .extbase-debugger-tree input:checked~.extbase-debug-header:before{background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTIgMTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDEyIDEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6Izg4ODg4ODt9PC9zdHlsZT48cGF0aCBpZD0iQm9yZGVyIiBjbGFzcz0ic3QwIiBkPSJNMTEsMTFIMFYwaDExVjExeiBNMTAsMUgxdjloOVYxeiIvPjxnIGlkPSJJbm5lciI+PHJlY3QgeD0iMiIgeT0iNSIgY2xhc3M9InN0MCIgd2lkdGg9IjciIGhlaWdodD0iMSIvPjwvZz48L3N2Zz4=)}
        .extbase-debugger{display:block;text-align:left;background:#2a2a2a;border:1px solid #2a2a2a;box-shadow:0 3px 0 rgba(0,0,0,.5);color:#000;margin:20px;overflow:hidden;border-radius:4px}
        .extbase-debugger-floating{position:relative;z-index:999}
        .extbase-debugger-top{background:#444;font-size:12px;font-family:monospace;color:#f1f1f1;padding:6px 15px}
        .extbase-debugger-center{padding:0 15px;margin:15px 0;background-image:repeating-linear-gradient(to bottom,transparent 0,transparent 20px,#252525 20px,#252525 40px)}
        .extbase-debugger-center,.extbase-debugger-center .extbase-debug-string,.extbase-debugger-center a,.extbase-debugger-center p,.extbase-debugger-center pre,.extbase-debugger-center strong{font-size:12px;font-weight:400;font-family:monospace;line-height:20px;color:#f1f1f1}
        .extbase-debugger-center pre{background-color:transparent;margin:0;padding:0;border:0;word-wrap:break-word;color:#999}
        .extbase-debugger-center .extbase-debug-string{color:#ce9178;white-space:normal}
        .extbase-debugger-center .extbase-debug-type{color:#569CD6;padding-right:4px}
        .extbase-debugger-center .extbase-debug-unregistered{background-color:#dce1e8}
        .extbase-debugger-center .extbase-debug-filtered,.extbase-debugger-center .extbase-debug-proxy,.extbase-debugger-center .extbase-debug-ptype,.extbase-debugger-center .extbase-debug-scope{color:#fff;font-size:10px;line-height:12px;padding:2px 4px;margin-right:2px;position:relative;top:-1px}
        .extbase-debugger-center .extbase-debug-scope{background-color:#497AA2}
        .extbase-debugger-center .extbase-debug-ptype{background-color:#698747}
        .extbase-debugger-center .extbase-debug-dirty{background-color:#FFFFB6}
        .extbase-debugger-center .extbase-debug-filtered{background-color:#4F4F4F}
        .extbase-debugger-center .extbase-debug-seeabove{text-decoration:none;font-style:italic}
        .extbase-debugger-center .extbase-debug-property{color:#f1f1f1}
    </style>
    <div class="extbase-debugger extbase-debugger-floating">
    <div class="extbase-debugger-top">xml error</div>
    <div class="extbase-debugger-center">
        <pre dir="ltr">NULL</pre>
    </div>
</div>
{"globalLaufschrift":"","wochentage":[]}

To my opinion, there is nothing we can really do about it. Option one - current state - is to fail loudly and to signal to clients that something went wrong. Option two - best-effort parsing of the API response - would recover exactly zero meals, which does not really justify the work required to implement the heuristic.

f4lco commented 6 years ago

I noticed that occasionally they keep their debug preamble together with valid meals and break their own website. Apparently this is subject to 'Guru Meditation':

d.a.post(e.state.dataUrl, n).then(function(t) {
    200 === t.status && (e.commit("initDataFromApi", t.data),
    e.commit("updateEtageData"),
    e.commit("updateElsTags"),
    e.commit("updateFreitagsModus"),
    e.commit("updateMealsAfterAllSettings"),
    e.commit("sortOutMeals"),
    e.commit("mapMealsToSpeiseplan"))
}).catch(function(t) {
    console.log("Guru-Meditation: Fehler beim laden der JSON-Daten"),
    console.log(t),
    e.commit("initDataApiFailed")
})

Also the 'empty meals' case is apparently not anticipated from their side (see JSON snippet from previous comment), since in this case ajaxData fails to populate:

initDataFromApi: function(e, t) {
    e.fullAjaxObj = t,
    e.globalLaufschrift = t.globalLaufschrift,
    e.ajaxData = t.wochentage[e.day].datum.angebote,
    e.datumData = t.wochentage[e.day].datum,
    e.ajaxWorking = !0
}

(both are excerpts of the pretty-printed source of the canteen website's JS). Both observations were made for Wildau on 2018-11-13.