| 18 | // oRPC to decode only 2xx responses; |
| 19 | // - link wrapper: the one residual throw (a 2xx body oRPC can't decode) -> mapOrpcError. |
| 20 | export function createOpenApiClient(http: HttpClient): OpenApiClient { |
| 21 | const link = new OpenAPILink(contract, { |
| 22 | url: http.baseURL, |
| 23 | fetch: async (req, init) => { |
| 24 | const res = await http.request(req, init) |
| 25 | if (!res.ok) |
| 26 | throw await classifyResponse(req, res) |
| 27 | return res |
| 28 | }, |
| 29 | }) |
| 30 | return createORPCClient<OpenApiClient>({ |
| 31 | call: (path, input, options) => link.call(path, input, options).catch(mapOrpcError), |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | // Non-2xx and transport failures already arrive as BaseError (from the fetch wrapper / transport) |
| 36 | // and re-throw unchanged; the only residual is a 2xx body oRPC failed to decode. |