gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3e3d5a553e3d5a55mission ST1: stall diagnosismre3e3d5a55/plugins/fetch/README.md

2.1 KB

  1. # hl:fetch
  2. `fetch(url, options)` makes an HTTP or HTTPS request and waits for the answer.
  3. ## When the connection fails
  4. A refused connection, an unknown host, a connect timeout, a reset by the peer and a TLS
  5. verification failure are all raised as an ordinary located error. The message names the method,
  6. the URL and the reason, for example
  7. `hl:fetch POST http://127.0.0.1:9/x: connection refused`,
  8. `hl:fetch GET http://nonexistent.invalid/x: could not resolve host` or `hl:fetch GET http://10.255.255.1/x: timed out`.
  9. The error can be caught with `on Error(e)`, in a plain program and inside a request handler alike.
  10. When the handler has absorbed the error, `fetch` gives back `null`, so the code can answer the failure itself:
  11. ```hybriel
  12. import { NativeHttpServer, Response } from 'hl:http1'
  13. import { fetch } from 'hl:fetch'
  14. inherit NativeHttpServer
  15. port = 8080
  16. on Error(e) { console.log('fetch failed: ' + e.message) }
  17. on request(req) {
  18. let res = fetch('http://127.0.0.1:9/x', { method = 'POST' json = { a = 1 } })
  19. if (res == null) { return new Response('upstream is down', { status = 502 }) }
  20. return new Response(res.text())
  21. }
  22. listen()
  23. ```
  24. Without an `on Error` handler the error is not caught. That is the language rule: the request then ends
  25. with the framework's `500` answer carrying the located message, and the server keeps serving.
  26. ## A failure as a value
  27. Import `tryFetch` from `hl:fetch` to handle a failed exchange without `on Error`.
  28. It accepts fetch's options and waits for completion. Every HTTP reply, including
  29. 404 or 500, has the same response and text()/json() readers as fetch. Connection,
  30. DNS, TLS and timeout failures return exactly `{ ok = false, status = 0, error }`.
  31. The error is fetch's message without its call site, for example
  32. `hl:fetch GET http://127.0.0.1:9/x: connection refused`. Native fetch is unchanged.
  33. The JS target and browser use the host Fetch API with the same response shape
  34. and whole-exchange `timeoutMs`. Browsers enforce CORS and expose only a generic
  35. network reason for many failures. `caFile` is supported only by the native engine.
  36. `tryFetch` waits even with `stream = true`; use fetchStart for native chunk events.

Branches

Latest commits

  • 3e3d5a55mission ST1: stall diagnosismre
  • 9c3180eblog+status: RV28d measured after deploymre
  • fdf10b1alog: RV28d deployed on day38bmre
  • 320005e9log: RV28d merged, deploy runningmre
  • a8fef27dRV28d: reportmre
  • 2bae8373RV28d: re-vendor Hybriel set day38b (source 1e554d75, bin 5ff2a46d)mre
  • 16b3354aMerge branch 'main' into rv28cmre
  • 6f4f27d8log: RV28d started (day38b)mre
  • e6cf03ffmission RV28d: rv28c onto day38bmre
  • 3ccaee19status: live sweep freeze, waiting for Apollomre
  • 49f76ecblog: watch toggle slowness = session sweep freeze (tracker#50)mre
  • 3daf6eddlog: day37 live, still waiting for day39mre
  • 796ba672records: #277 slips to day39mre
  • a9eb9827records: mpackdb integrity clean, all 12 tablesmre
  • 6cf40dbdrecords: mpackdb integrity check, shows uncheckedmre
  • 1880f42arecords: day38 deploy may swap normallymre
  • 9d806e35records: mpackdb freeze until day38mre
  • a660239drecords: day37 lacks #277, wait for day38mre
  • b0abfdeaLOG: Anton hybriel#277 fix ready for day37mre
  • 7b5b2918Tracker: hybriel#277 fix comes in day37mre