@karedo-hq/agents 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karedo-hq/agents",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Centralized agent skills, rules, and commands for our engineering team",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,6 +32,36 @@ alwaysApply: false
32
32
  - Catch block: use `getErrorMessage(error)` from `@/lib/utils/get-error-message`
33
33
  - Never use `getErrorMessage()` on strings (causes double-quoting)
34
34
 
35
+ ### Safe JSON Parsing
36
+
37
+ Always use `safeJson()` from `@/lib/utils/safe-json` instead of raw `.json()`:
38
+
39
+ ```typescript
40
+ import { safeJson, SERVER_UNAVAILABLE_MESSAGE } from "@/lib/utils/safe-json";
41
+
42
+ // Error path
43
+ if (!res.ok) {
44
+ const errorResult = await safeJson<{ message?: string }>(res);
45
+ const errorMessage = errorResult.isSuccess
46
+ ? errorResult.data.message || "Fallback message"
47
+ : SERVER_UNAVAILABLE_MESSAGE;
48
+ return { isSuccess: false, isError: true, errorMessage };
49
+ }
50
+
51
+ // Success path
52
+ const result = await safeJson<ExpectedType>(res);
53
+ if (!result.isSuccess) {
54
+ return {
55
+ isSuccess: false,
56
+ isError: true,
57
+ errorMessage: SERVER_UNAVAILABLE_MESSAGE,
58
+ };
59
+ }
60
+ const data = result.data;
61
+ ```
62
+
63
+ **Why:** When infrastructure (load balancers, CDN) returns HTML error pages (502, 503), raw `.json()` throws cryptic "Unexpected token '<'" errors. `safeJson()` handles this gracefully with user-friendly German messages.
64
+
35
65
  ### Fetch Headers
36
66
 
37
67
  ```typescript