Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 773 Bytes

README.md

File metadata and controls

34 lines (25 loc) · 773 Bytes

FluentSwitch

Build Status

Better way to do switching.

Installation

npm i fluent-switch

Usage

No fallback

  FluentSwitch
    .createFrom(error)
    .case(e => e instanceof TimeoutError, e => log.error('timeout', e))
    .case(e => e instanceof ConnectionError, () => e => log.error('connection', e))
    .execute()

With fallback

  FluentSwitch
    .createFrom(error)
    .case(e => e instanceof TimeoutError, e => log.error('timeout', e))
    .case(e => e instanceof ConnectionError, () => e => log.error('connection', e))
    .else(e => log.error('Unknown error', e))
    .execute()