Skip to content

v6.0.0

Choose a tag to compare

@alexop1000 alexop1000 released this 09 Aug 13:05
· 63 commits to master since this release

v6.0.0

Major release with improved error handling, new endpoints, and Zod v4.

Highlights

  • Updated to Zod v4.
  • Added v2 Trades routes.
  • Regenerated and refreshed all endpoints.
  • Strongly-typed, first-class error handling across the client.

Breaking changes

  • fetchApi return types
    • Default: now returns a union of success or error.
      • Before: assumed success or returned ad‑hoc error strings.
      • Now: Promise<ExtractResponse<S> | AnyError>.
    • With throwOnError: true (and not returnRaw: true): only returns success, throws on errors.
      • Promise<ExtractResponse<S>>.
    • With returnRaw: true: returns raw response wrapper (and bypasses error parsing).
      • Promise<TypedJsonResponse<ExtractResponse<S>>>.
  • fetchApiSplit type
    • Now: Promise<T[] | AnyError> (not Array<T | AnyError>).
  • fetchApiPages type
    • Now: Promise<ExtractResponse<S>[] | AnyError>.
    • Generator fetchApiPagesGenerator: yields ExtractResponse<S> | AnyError.
  • Error mapping via endpoint.errors no longer returns description strings. Errors are returned as structured AnyError or thrown (when throwOnError is used).

New exports

  • isAnyErrorResponse(value): value is AnyError
  • AnyError type

Error handling improvements

  • Error parsing uses parse-roblox-errors:
    • For roblox.com endpoints:
      • apis.roblox.comparseBEDEV2Error
      • other roblox.comparseBEDEV1Error
    • Non‑Roblox domains: generic textual AnyError (best effort from JSON/text).
  • Only successful responses are cached.
  • returnRaw: true short-circuits before error parsing and returns the raw response.

Migration guide

  • Default usage (non-throwing):

    const res = await fetchApi(myEndpoint, params);
    if (isAnyErrorResponse(res)) {
      // handle AnyError
      console.error(res.message);
      return;
    }
    // res is the success payload here
  • Throwing flow (recommended for happy-path code):

    const data = await fetchApi(myEndpoint, params, { throwOnError: true });
    // data is the success payload, errors throw
  • Raw flow (no error parsing, inspect the Response yourself):

    const resp = await fetchApi(myEndpoint, params, { returnRaw: true });
    const json = await resp.json();
  • Split and pages helpers:

    • fetchApiSplit: now T[] | AnyError
      const res = await fetchApiSplit(ep, params, { items: 100 }, r => r.data);
      if (isAnyErrorResponse(res)) { /* error */ } else { /* res is T[] */ }
    • fetchApiPages: now ExtractResponse<S>[] | AnyError
      const pages = await fetchApiPages(ep, params);
      if (isAnyErrorResponse(pages)) { /* error */ } else { /* pages is array */ }

Endpoint updates

  • Added v2 Trades routes.
  • Regenerated all endpoints from the latest specs (names, params, and response types may have shifted to match upstream).

Zod v4

  • Upgraded to Zod v4. Ensure your consumers and build pipeline are compatible with Zod v4.

Notes

  • For non‑throwing code, prefer the isAnyErrorResponse guard for type‑safe error branching.
  • For throwing code, use { throwOnError: true } to keep your code linear and avoid unions.
  • For custom error handling/parsing, use { returnRaw: true } and handle the Response directly.

Full Changelog: v5.0.0...v6.0.0