@hanakla/rescue
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@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] })

Readme

Keywords

none

Package Sidebar

Install

npm i @hanakla/rescue

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

6.6 kB

Total Files

9

Last publish

Collaborators

  • hanakla