Skip to content

Commit

Permalink
Update styling of message dependent on running environment
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmsnell committed Mar 2, 2017
1 parent 3f64db7 commit 9186e67
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions server/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

Expand Down

0 comments on commit 9186e67

Please sign in to comment.