1616 along with this program. If not, see <https://www.gnu.org/licenses/>.
1717*/
1818
19+ const stringify = require ( 'json-stringify-safe' ) ;
20+
1921let originalError = Error ;
2022class ApplicationErrorExtension extends Error {
2123 constructor ( message , rawCode , ...args ) {
2224 const code = rawCode || typeof message === 'string' && message || typeof message === 'object' && message . code || null ;
2325
2426 const codeString = `(${ code || 'UnspecifiedApplicationErrorCode' } )` ;
25- const stringErrorMessage = `${ codeString } : ${ JSON . stringify ( message || '' ) } ` ;
27+ const stringErrorMessage = `${ codeString } : ${ stringify ( message || '' ) } ` ;
2628 super ( stringErrorMessage , ...args ) ;
2729
2830 if ( typeof originalError . captureStackTrace !== 'undefined' ) {
@@ -39,7 +41,7 @@ class ApplicationErrorExtension extends Error {
3941
4042 toString ( ) {
4143 const codeString = `(${ this . code || 'UnspecifiedApplicationErrorCode' } )` ;
42- return `${ codeString } : ${ JSON . stringify ( this . message || '' ) } ` ;
44+ return `${ codeString } : ${ stringify ( this . message || '' ) } ` ;
4345 }
4446
4547 toJSON ( ) {
@@ -75,7 +77,7 @@ Error.create = function(errorObject, code) {
7577Error . prototype . create = Error . create ;
7678Error . prototype . toString = function ( ) {
7779 const codeString = this . code ? ` (${ this . code } )` : '' ;
78- return this . message ? `ErrorObjectPolyFill${ codeString } : ${ JSON . stringify ( this . message ) } ` : 'ErrorObjectPolyFill' ;
80+ return this . message ? `ErrorObjectPolyFill${ codeString } : ${ stringify ( this . message ) } ` : 'ErrorObjectPolyFill' ;
7981} ;
8082Error . prototype . inspect = Error . prototype . toString ;
8183Error . prototype . toJSON = function ( ) {
0 commit comments