↑ Usage Guide Index | ← Core API OVERVIEW
Error taxonomy and handling patterns across HTTP, SpecManager, AutoLoader, Modules, BatchLoader, and SyncLoader.
Design principle: do not throw on normal HTTP non‑2xx — prefer returning structured results (
format: 'full') and let callers decide. Hard errors are reserved for programmer/config errors (e.g., invalid method, duplicate IDs).
| Area | When it happens | Error surface / semantics | Caller action |
|---|---|---|---|
| HTTP (request build) | Unsupported helper for method kind (e.g., body in GET) | Throws Invalid HTTP method ... for _noBodyRequest/_bodyRequest |
Fix call site; use correct helper |
| HTTP (timeout/abort) | Timeout elapsed or external AbortSignal fired |
Native AbortError rejection |
Catch and retry/cancel as needed |
| HTTP (non‑2xx) | Server responds !ok |
No throw by default; use format:'full' to inspect |
Check ok/status/body and branch |
| HTTP (JSON parse) | content-type JSON but invalid body |
Parser throws | Catch; consider format:'raw' |
| AutoLoader | Unsupported or missing x-type |
Throws Error('unsupported or missing x-type: ...') |
Verify loader availability or add a loader |
| SpecManager | Spec not loaded / operationId missing |
Throws Error('spec not found') / Error('operation not found') |
Load/refresh spec, fix ID |
| Modules | Dynamic import failed | Rejected Promise from import() |
Catch; verify URL and CORS |
| BatchLoader (preflight) | Missing/duplicate IDs; unsupported method | Throws with descriptive message | Fix batch list |
| BatchLoader (per‑item) | Handler returns false |
Marks item failed; triggers onFail at end |
Branch in onFail |
| SyncLoader | N/A (controller) | No throws; state tracked via loaded/failed/success |
Poll or use callbacks |
- Do not throw on normal HTTP responses. Use
format: 'full'when you needok,status, headers, and parsedbodyfor routing error flows. - Throw early on programmer errors. Incorrect method usage, invalid batch definitions, and missing spec/operation IDs throw with clear messages.
- Failure ≠ exception in Batch/Sync. In Batch flows, only a per‑item handler that returns
falsemarks failure; otherwise the item is considered successful and stored in context.
_noBodyRequestonly allows GET/HEAD/OPTIONS/DELETE;_bodyRequestonly allows POST/PUT/PATCH. Passing the wrong method throws immediately with a descriptive message.
Fix: call an appropriate helper.
- If a
timeoutis set (or an externalAbortSignalis provided), the request may reject with a nativeAbortError.
Fix: catch and decide whether to retry, surface, or cancel dependent work.
- The HTTP layer does not throw for
!res.ok. Preferformat: 'full'and checkok/status.
const res = await net.http.get('/v1/users/me', { format: 'full' });
if (!res.ok) {
if (res.status === 401) return reauth();
return showError(res.body?.message || 'Request failed');
}
return res.body;- If
content-typeis JSON but the body is invalid, the JSON parser will throw. You can switch toformat:'raw'to inspect the raw stream/text.
- Loading from a URL/object requires a supported
x-type. Missing or unsupported types result in a thrownError. - When
method:'post'is provided, ensuredatamatches the server expectations; transport errors surface like HTTP errors above.
- Spec not found: calling
call(specId, ...)before a successfulload()throws. - Operation not found: the provided
operationIdisn’t present in the spec; throws with a clear message. - Path param validation: missing required
{path}variables should throw before dispatch.
Caller guidance: verify IDs, re‑load/refresh specs after changes, and prefer format:'full' for inspectable responses.
- Dynamic
import(url)rejects on network/CORS/parse errors. The manager logs a concise context line and re‑throws.
Caller guidance: wrap await net.modules.load(...) in try/catch; consider using { reload:true } during hot‑reload flows.
- Missing
idorurl - Duplicate
id - Unsupported HTTP
method(only'get' | 'post'are valid)
- Only a per‑item handler that returns
falsemarks the item failed. Failure triggers the batch’sonFailcallback once all required IDs have resolved. - By default, results are stored in
context[id]for later retrieval; custom batch handlers may change this behavior.
Tip: use opts: { format:'full' } inside items to branch on res.ok without exceptions.
set(id)marks a task as completed.fail(id)flags a task as failed (still counts toward completion).- Final callback routing: if any task failed,
failis used (when provided), otherwiseload. wrapper(id, handler)interpretshandler(...args) === falseas failure, then callsset(id)automatically.
const http = net.http;
async function safeJSON(path, opts) {
const res = await http.get(path, { format: 'full', ...opts });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.body;
}await net.batch.run([
{ id: 'cfg', url: '/cfg.json', opts: { format: 'full' }, handler: res => res.ok ? res.body : false },
{ id: 'i18n', url: '/i18n/en.json', opts: { format: 'full' }, handler: res => res.ok ? res.body : false }
], ({ context }) => bootstrap(context), ({ controller }) => showBanner(controller.fail));try {
const utils = await net.modules.load('utils', '/lib/utils.js');
utils.ready();
} catch (e) {
console.error('Module load failed', e);
}Use these in docs/UI; runtime throws are plain Error unless you layer your own classes.
E_HTTP_UNSUPPORTED_METHODE_HTTP_INVALID_FETCH_OPTIONE_HTTP_ABORTEDE_SPEC_NOT_FOUNDE_SPEC_OPERATION_NOT_FOUNDE_SPEC_PATH_PARAM_MISSINGE_AUTOLOADER_UNSUPPORTED_TYPEE_MODULE_LOAD_FAILEDE_BATCH_DUPLICATE_IDE_BATCH_INVALID_METHOD
- Verify method helper matches the intended verb.
- Use
format:'full'when debugging — surfacesstatus,headers, andelapsedMs. - Watch for CORS in module/spec loads (imports and fetch share origin policy).
- In Batch flows, confirm your handlers return
falseon failure. - Prefer explicit path params in spec calls and assert required fields in dev.