Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 591 Bytes

error.md

File metadata and controls

26 lines (17 loc) · 591 Bytes

Error

Error instance

error/is

Confirms if given object is a native error object

const isError = require("type/error/is");

isError(new Error()); // true
isError({ message: "Fake error" }); // false

error/ensure

If given argument is an error object, it is returned back. Otherwise TypeError is thrown.

const ensureError = require("type/error/ensure");

const someError = new Error("Some error");
ensureError(someError); // someError
ensureError({ message: "Fake error" }); // Thrown TypeError: [object Object] is not an error object