gitoria
All repositories: gitoria
2.1 KB
# hl:fetch`fetch(url, options)` makes an HTTP or HTTPS request and waits for the answer.## When the connection failsA refused connection, an unknown host, a connect timeout, a reset by the peer and a TLSverification failure are all raised as an ordinary located error. The message names the method,the URL and the reason, for example`hl:fetch POST http://127.0.0.1:9/x: connection refused`,`hl:fetch GET http://nonexistent.invalid/x: could not resolve host` or `hl:fetch GET http://10.255.255.1/x: timed out`.The error can be caught with `on Error(e)`, in a plain program and inside a request handler alike.When the handler has absorbed the error, `fetch` gives back `null`, so the code can answer the failure itself:```hybrielimport { NativeHttpServer, Response } from 'hl:http1'import { fetch } from 'hl:fetch'inherit NativeHttpServerport = 8080on Error(e) { console.log('fetch failed: ' + e.message) }on request(req) {let res = fetch('http://127.0.0.1:9/x', { method = 'POST' json = { a = 1 } })if (res == null) { return new Response('upstream is down', { status = 502 }) }return new Response(res.text())}listen()```Without an `on Error` handler the error is not caught. That is the language rule: the request then endswith the framework's `500` answer carrying the located message, and the server keeps serving.## A failure as a valueImport `tryFetch` from `hl:fetch` to handle a failed exchange without `on Error`.It accepts fetch's options and waits for completion. Every HTTP reply, including404 or 500, has the same response and text()/json() readers as fetch. Connection,DNS, TLS and timeout failures return exactly `{ ok = false, status = 0, error }`.The error is fetch's message without its call site, for example`hl:fetch GET http://127.0.0.1:9/x: connection refused`. Native fetch is unchanged.The JS target and browser use the host Fetch API with the same response shapeand whole-exchange `timeoutMs`. Browsers enforce CORS and expose only a genericnetwork reason for many failures. `caFile` is supported only by the native engine.`tryFetch` waits even with `stream = true`; use fetchStart for native chunk events.
Branches
Latest commits
- 24b479e7W60: record final gates, Chrome failures and AE evidencemre
- 5e11184cW60: record partial validation, framework gaps and cleanupmre
- 20fe13fagitoria#33: centralize login and tickets connection statemre
- 859754c0gitoria#29: retain the offline note and record the framework gapmre
- d140bc04gitoria#30: reproduce the upsert ordering constraintmre
- 6960e8f8gitoria#28: keep form values in bound component membersmre
- 0db27200gitoria#32: share character checks and environment lookupmre
- 452f6a1amission W60: logic clean-upsmre
- 1448c899log: cleanup, #49 GPTBot, tracker mentions on #36mre
- fcf95936log: v1.5.1 provenmre
- 22105420log: W51b livemre
- 7e8aabeareport: W51b pull source verificationmre
- 6c18de76fix: preserve pull sources across containing branchesmre
- fc36fa2elog: W51b pull source bugmre
- 56bc1220log: v1.5.1 livemre
- 845fc0aareport: W51mre
- 83127391fix: return v1.5.1 app and merge error detailsmre
- b07d0e97log: W51 v1.5.1 startedmre
- 0b417d06docs: apps-api v1.5 user tokens (#48, W49)mre
- d046940alog: vinzenz contract note sentmre