element-plus/packages/utils/error.ts

25 lines
682 B
TypeScript
Raw Normal View History

import { isString } from './types'
2020-08-19 11:05:40 +08:00
class ElementPlusError extends Error {
constructor(m: string) {
super(m)
2020-09-14 10:03:33 +08:00
this.name = 'ElementPlusError'
2020-08-19 11:05:40 +08:00
}
}
export function throwError(scope: string, m: string): never {
2020-09-14 10:03:33 +08:00
throw new ElementPlusError(`[${scope}] ${m}`)
}
export function debugWarn(err: Error): void
export function debugWarn(scope: string, message: string): void
export function debugWarn(scope: string | Error, message?: string): void {
if (process.env.NODE_ENV !== 'production') {
const error: Error = isString(scope)
? new ElementPlusError(`[${scope}] ${message}`)
: scope
// eslint-disable-next-line no-console
console.warn(error)
}
2020-08-19 11:05:40 +08:00
}