Created
November 13, 2020 00:21
-
-
Save lefam/b4ceb647e0b44c0e32ba5ee40c3053db to your computer and use it in GitHub Desktop.
Function to use with JSON.stringify to print Error objects (typescript)
This file contains 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
function replaceErrors(key:any, value:any) { | |
if (value instanceof Error) { | |
var error : {[k: string]: any } = {}; | |
Object.getOwnPropertyNames(value).forEach(function (key) { | |
error[key] = (value as {[k: string]: any })[key]; | |
}); | |
return error; | |
} | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use: