helpers.js
// Returns [item, null] if successful, where item contains final object saved.
Returns [item, null] if successful, where item contains final object saved.
Returns [ item null ] if successful where item contains final object saved .
async function submit(sreq, method, item) {
    try {
        let res = await fetch(sreq, {
            method: method,
            headers: {"Content-Type": "application/json"},
            body: JSON.stringify(item),
        });
        if (!res.ok) {
            let s = await res.text();
            let err = new Error(s);
            err.status = res.status;
            return [null, err];
        }
        let saveditem = await res.json();
        return [saveditem, null];
    } catch(err) {
        return [null, err];
    }
}
async function submit ( sreq , method , item ) { try { let res = await fetch ( sreq , { method : method , headers : { "Content-Type" : "application/json" } , body : JSON . stringify ( item ) , } ) ; if ( ! res . ok ) { let s = await res . text ( ) ; let err = new Error ( s ) ; err . status = res . status ; return [ null , err ] ; } let saveditem = await res . json ( ) ; return [ saveditem , null ] ; } catch ( err ) { return [ null , err ] ; } }
Returns [item, null] if successful, where item contains final object saved.
Returns [ item null ] if successful where item contains final object saved .