error-handler.ts
May 6, 2021•120 words
/**
* This file handles errors
* The purpose of it is allow for graceful failing,
* and to log issues using a third-party if necessary
* App monitoring will allow for errors to be addressed
*/
const handleError = (humanMessage: string, where: string = 'App', errObj?: Error) => {
const env = process.env.NODE_ENV || '';
if (env.match(/^(prod|production|live)$/)) {
// App is running in production
// Call to app monitoring or error tracking service
// TODO
} else {
// App is running in development
/* eslint-disable no-console */
console.log(
`\n%c Warning Caught in: ${where} %c\n${humanMessage}\n${errObj || ''}`,
'color: #fabb00; background: #b04646; border-radius: 5px; padding: 3px;',
'color: #fabb00; padding: 5px 3px 0;',
);
}
};
export default handleError;