Skip to content

Commit bd473c0

Browse files
committed
feat: enhance fetch commands to include response status and error handling
1 parent a7497a4 commit bd473c0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

schema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ websocket|command|CLOSE|close|handle(WebSocket):handle|{ const ws = websockets[h
173173
# ------------------------------------------------------------------------------
174174
fetch|event|SUCCESS|handle(FetchRequest):id string:data
175175
fetch|event|ERROR|handle(FetchRequest):id string:error
176-
fetch|command|GET|get|string:url RET:handle(FetchRequest)|{ const id = (window.webcc_next_id = (window.webcc_next_id || 0) + 1); fetch(url).then(r => { if(!r.ok) throw new Error(r.status + ' ' + r.statusText); return r.text(); }).then(d => push_event_fetch_SUCCESS(id, d)).catch(e => push_event_fetch_ERROR(id, e.toString())); return id; }
177-
fetch|command|POST|post|string:url string:body RET:handle(FetchRequest)|{ const id = (window.webcc_next_id = (window.webcc_next_id || 0) + 1); fetch(url, { method: 'POST', body: body }).then(r => { if(!r.ok) throw new Error(r.status + ' ' + r.statusText); return r.text(); }).then(d => push_event_fetch_SUCCESS(id, d)).catch(e => push_event_fetch_ERROR(id, e.toString())); return id; }
176+
fetch|command|GET|get|string:url RET:handle(FetchRequest)|{ const id = (window.webcc_next_id = (window.webcc_next_id || 0) + 1); fetch(url).then(r => r.text().then(d => ({ ok: r.ok, status: r.status, statusText: r.statusText, data: d }))).then(res => { if(res.ok) push_event_fetch_SUCCESS(id, res.data); else push_event_fetch_ERROR(id, res.data && res.data.length ? res.data : (res.status + ' ' + res.statusText)); }).catch(e => push_event_fetch_ERROR(id, e.toString())); return id; }
177+
fetch|command|POST|post|string:url string:body RET:handle(FetchRequest)|{ const id = (window.webcc_next_id = (window.webcc_next_id || 0) + 1); fetch(url, { method: 'POST', body: body }).then(r => r.text().then(d => ({ ok: r.ok, status: r.status, statusText: r.statusText, data: d }))).then(res => { if(res.ok) push_event_fetch_SUCCESS(id, res.data); else push_event_fetch_ERROR(id, res.data && res.data.length ? res.data : (res.status + ' ' + res.statusText)); }).catch(e => push_event_fetch_ERROR(id, e.toString())); return id; }
178178

179179
# ------------------------------------------------------------------------------
180180
# IMAGES

0 commit comments

Comments
 (0)