Last active
July 3, 2025 22:57
-
-
Save rw3iss/4e3fff05702bd10e27abf2c9cc96acb8 to your computer and use it in GitHub Desktop.
getInnerError
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Finds the inner-most error, returning a string. | |
export const getInnerError = (e, log?) => { | |
if (!e) return undefined; | |
const _log = typeof log !== 'undefined' ? (typeof log == "function" ? log : console.log) : undefined; | |
if (_log) _log(e); | |
if (typeof e == "string") return e; | |
if (Array.isArray(e)) return e.map(_e => getInnerError(_e, log)).join(", "); | |
// leave these separate so it recursesq through to each to always ensure a message can be found. | |
return ( | |
getInnerError(e.error, log) || | |
getInnerError(e.errors, log) || | |
getInnerError(e.data, log) || | |
getInnerError(e.response, log) || | |
getInnerError(e.message, log) || | |
getInnerError(e.result, log) || | |
getInnerError(e.reason, log) || | |
"Unknown error." | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment