Ensures a value is an Error, throws if not
确保值是 Error,如果不是则抛出错误
The value to check. 要检查的值
Optional
Custom error message if the value is not an Error. 如果值不是 Error 时的自定义错误消息
The value if it is an Error. 如果是 Error 则返回该值
Error if the value is not an Error. 如果值不是 Error 则抛出错误
toError(new Error('test')) // => Error('test')toError('not an error', 'Expected an Error') // => throws Error('Expected an Error') Copy
toError(new Error('test')) // => Error('test')toError('not an error', 'Expected an Error') // => throws Error('Expected an Error')
Ensures a value is an Error, throws if not
确保值是 Error,如果不是则抛出错误