fix(errors): classify failures from the first reported system code (#14686)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-11-26 17:28:41 +08:00
1 parent 8d302d2dad
commit a8fdc0961b
17 files changed
+73 -105

No files matched your search

+13 -5
View File
@@ -1,7 +1,15 @@
/** Read the string code reported by a caught object, including a plain object. */
export const reportedSystemCode = (cause: unknown): string | undefined => {
if (typeof cause !== "object" || cause === null || !("code" in cause))
return undefined;
const code: unknown = cause.code;
const readStringCode = (value: object): string | undefined => {
if (!("code" in value)) return undefined;
const code: unknown = value.code;
return typeof code === "string" ? code : undefined;
};
/** Read the string code reported by a caught object, including a plain object. */
export const reportedSystemCode = (cause: unknown): string | undefined =>
typeof cause === "object" && cause !== null
? readStringCode(cause)
: undefined;
/** Read a system code only when the caller caught an Error. */
export const systemCodeFromError = (cause: unknown): string | undefined =>
cause instanceof Error ? readStringCode(cause) : undefined;