2022-03-06 22:20:56 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 10:01:17 +08:00
|
|
|
export function throwError(scope: string, m: string): never {
|
2020-09-14 10:03:33 +08:00
|
|
|
throw new ElementPlusError(`[${scope}] ${m}`)
|
|
|
|
}
|
|
|
|
|
2022-03-06 22:20:56 +08:00
|
|
|
export function debugWarn(err: Error): void
|
|
|
|
export function debugWarn(scope: string, message: string): void
|
|
|
|
export function debugWarn(scope: string | Error, message?: string): void {
|
2021-09-09 11:49:48 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2022-03-06 22:20:56 +08:00
|
|
|
const error: Error = isString(scope)
|
|
|
|
? new ElementPlusError(`[${scope}] ${message}`)
|
|
|
|
: scope
|
2021-09-09 11:49:48 +08:00
|
|
|
// eslint-disable-next-line no-console
|
2022-03-06 22:20:56 +08:00
|
|
|
console.warn(error)
|
2021-09-09 11:49:48 +08:00
|
|
|
}
|
2020-08-19 11:05:40 +08:00
|
|
|
}
|