1.0.4 • Published 2 years ago

@hanakla/rescue v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-pre.1

3 years ago