Files
2019-10-17 12:36:15 +09:00

24 lines
578 B
TypeScript

import chalk from 'chalk';
import { metrics, shouldCollectMetrics } from '../metrics';
const metric = metrics();
export default function error(
...input: string[] | [{ slug: string; message: string }]
) {
let messages = input;
if (typeof input[0] === 'object') {
const { slug, message } = input[0];
messages = [message];
if (slug) {
messages.push(`> More details: https://err.sh/now/${slug}`);
}
}
if (shouldCollectMetrics) {
metric.exception(messages.join('\n')).send();
}
return `${chalk.red('> Error!')} ${messages.join('\n')}`;
}