convert-unknown-catch-to-error
v1.0.3
Published
Utility function to convert an unknown value in try/catch's catch block to Error
Maintainers
Readme
convert-unknown-catch-to-error
Utility function to convert an unknown value in try/catch's catch block to Error.
Usage
This library lets you use the utility function either by importing or running a side effect to set $convertUnknownCatchToError utility function on globalThis so that it can be used anywhere in your codebase.
Use as global value
// In your root entry file
// import module for side effect (makes this available globally)
import "convert-unknown-catch-to-error/global";
// Any file in your codebase without any import
try {
...
} catch (e) {
const error = $convertUnknownCatchToError(e);
}Use as module import
import { convertUnknownCatchToError } from "convert-unknown-catch-to-error";
try {
...
} catch (e) {
const error = $convertUnknownCatchToError(e);
}