Socket
Book a DemoInstallSign in
Socket

@hanakla/rescue

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hanakla/rescue

TypeScript one-line try-catch handling helper

latest
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

@hanakla/rescue

Type safe one line try-catch handler

Example

import { rescue } from '@hanakla/rescue'

const result = rescue(() => /* success or raise error process */)
if (result.error) { console.warn(result.error) }
if (result.result) { console.log(result.result) }

// Spread style
const [result, error] = rescue(() => /* ... */)

// Support async function
const [result, error] = await rescue(async () => /* async process */)

// Error type expection
class YourError extends Error {}

// when raises `YourError`, rescue handle and return result/
// Otherwise, rescue is not handle error it's rethrowing.
const result = rescue(() => /* process */, { expects: [YourError] })

FAQs

Package last updated on 08 Feb 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