@karedo-hq/agents 0.1.4 → 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
|
@@ -28,24 +28,39 @@ alwaysApply: false
|
|
|
28
28
|
|
|
29
29
|
### Error Handling
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
- API errors (`!res.ok`): use `resJSON.message` directly
|
|
32
|
+
- Catch block: use `getErrorMessage(error)` from `@/lib/utils/get-error-message`
|
|
33
|
+
- Never use `getErrorMessage()` on strings (causes double-quoting)
|
|
34
|
+
|
|
35
|
+
### Safe JSON Parsing
|
|
36
|
+
|
|
37
|
+
Always use `safeJson()` from `@/lib/utils/safe-json` instead of raw `.json()`:
|
|
32
38
|
|
|
33
39
|
```typescript
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
)
|
|
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
|
+
}
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
// Success path
|
|
52
|
+
const result = await safeJson<ExpectedType>(res);
|
|
53
|
+
if (!result.isSuccess) {
|
|
40
54
|
return {
|
|
41
55
|
isSuccess: false,
|
|
42
56
|
isError: true,
|
|
43
|
-
errorMessage,
|
|
57
|
+
errorMessage: SERVER_UNAVAILABLE_MESSAGE,
|
|
44
58
|
};
|
|
45
59
|
}
|
|
60
|
+
const data = result.data;
|
|
46
61
|
```
|
|
47
62
|
|
|
48
|
-
**
|
|
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.
|
|
49
64
|
|
|
50
65
|
### Fetch Headers
|
|
51
66
|
|