Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

catch-safe

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

catch-safe

Zero-dependency type-safe error handling utility

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

catch-safe

Inspired by and adapted from the example code in this article by Kent C. Dodds

Since TypeScript 4.4, catch clause variables default to the unknown type. This library provides a zero-dependency utility function which allows you to extract the error message in a type-safe manner when the variable is of type Error.

Installation

Install the package in your project:

# NPM
npm install catch-safe

# Yarn
yarn add catch-safe

# PNPM
pnpm add catch-safe

Usage

Import the getErrorMessage function from the catch-safe module and use it to get the error message (if it exists) from a catch block variable :

import { getErrorMessage } from 'catch-safe'

async function someAsyncFunction() {
  try {
    await runAsyncTask()
  } catch (err) {
    throw new Error(getErrorMessage(err))
  }
}

FAQs

Package last updated on 25 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc