helpers.js
// Returns [item, null] if successful, where item contains value returned from request.
Returns [item, null] if successful, where item contains value returned from request.
Returns [ item null ] if successful where item contains value returned from request .
async function find(sreq, fmt) {
    try {
        let res = await fetch(sreq, {method: "GET"});
        if (!res.ok) {
            if (res.status == 404) {
                return [null, null];
            }
            let s = await res.text();
            let err = new Error(s);
            err.status = res.status;
            return [null, err];
        }
        let v;
        if (!fmt || fmt == "json") {
            v = await res.json();
        } else {
            v = await res.text();
        }
        return [v, null];
    } catch(err) {
        return [null, err];
    }
}
async function find ( sreq , fmt ) { try { let res = await fetch ( sreq , { method : "GET" } ) ; if ( ! res . ok ) { if ( res . status == 404 ) { return [ null , null ] ; } let s = await res . text ( ) ; let err = new Error ( s ) ; err . status = res . status ; return [ null , err ] ; } let v ; if ( ! fmt || fmt == "json" ) { v = await res . json ( ) ; } else { v = await res . text ( ) ; } return [ v , null ] ; } catch ( err ) { return [ null , err ] ; } }
Returns [item, null] if successful, where item contains value returned from request.
Returns [ item null ] if successful where item contains value returned from request .