From 9186e67220fba8d402a5283b0acff51ab461d58c Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Wed, 1 Mar 2017 21:04:51 -0700 Subject: [PATCH] Update styling of message dependent on running environment Instead of showing the same message in the console as in the browser we can split the message into a styled and unstyled component. This commit does just that using visual styling in the in-browser error message to make it stand out among other warnings and messages. --- server/config/index.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/server/config/index.js b/server/config/index.js index e08fc64b03248d..d75a70bc510c8c 100644 --- a/server/config/index.js +++ b/server/config/index.js @@ -36,19 +36,29 @@ function config( key ) { return data[ key ]; } - const errorMessage = ( - `Could not find config value for key '${ key }'\n` + - `Please make sure that if you need it then it has a value assigned in 'config/_shared.json'` - ); - if ( 'development' === process.env.NODE_ENV ) { - throw new ReferenceError( errorMessage ); + throw new ReferenceError( + `Could not find config value for key '${ key }'\n` + + `Please make sure that if you need it then it has a default value assigned in 'config/_shared.json'` + ); } // display console error only in a browser // (not in tests, for example) if ( 'undefined' !== typeof window ) { - console.error( errorMessage ); + console.error( + `%cCore Error: ` + + `%cCould not find config value for key %c${ key }%c. ` + + `Please make sure that if you need it then it has a default value assigned in ` + + `%cconfig/_shared.json` + + `%c.`, + 'color: red; font-size: 120%', // error prefix + 'color: black;', // message + 'color: blue;', // key name + 'color: black;', // message + 'color: blue;', // config file reference + 'color: black' // message + ); } }