kayto_ts 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -224,6 +224,66 @@ const clientWithHooks = clientApi<CatsEndpoints>({
|
|
|
224
224
|
});
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
+
## Success Handling (Cats API)
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
async function fetchCatsUI() {
|
|
231
|
+
let loading = true;
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
const result = await client.get("/api/cats");
|
|
235
|
+
|
|
236
|
+
if (!result.ok) {
|
|
237
|
+
throw result.error;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const cats = result.responses[200];
|
|
241
|
+
|
|
242
|
+
if (!cats) {
|
|
243
|
+
throw new Error("Cats response is empty");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return cats;
|
|
247
|
+
} catch (error) {
|
|
248
|
+
// UI can show toast/snackbar here
|
|
249
|
+
throw error;
|
|
250
|
+
} finally {
|
|
251
|
+
loading = false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
async function createCatUI() {
|
|
258
|
+
let loading = true;
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
const result = await client.post("/api/cats", {
|
|
262
|
+
body: {
|
|
263
|
+
name: "Milo",
|
|
264
|
+
age: 2,
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
if (!result.ok) {
|
|
269
|
+
throw result.error;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const created = result.responses[201] ?? result.responses[200];
|
|
273
|
+
|
|
274
|
+
if (!created) {
|
|
275
|
+
throw new Error("Create cat payload is empty");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return created;
|
|
279
|
+
} catch (error) {
|
|
280
|
+
throw error;
|
|
281
|
+
} finally {
|
|
282
|
+
loading = false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
227
287
|
## Error Handling
|
|
228
288
|
|
|
229
289
|
All requests return a discriminated union:
|