mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
fix(errors): classify failures from the first reported system code (#14686)
This commit is contained in:
1 parent
8d302d2dad
commit
a8fdc0961b
17 files changed
+73
-105
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user