ts-condition-handler
v0.1.0
Published
Execute the corresponding handler by customized definition in a declarative way.
Downloads
88
Readme
ts-condition-handler
Execute the corresponding handler by customized definition in a declarative way.
Example
import { conditionHandler } from 'ts-condition-handler'
function main() {
try {
// do something that may throw an error in a specific type
doSomething()
} catch (err) {
conditionHandler(error)
.on(CustomerNotFound, handleCustomerNotFound)
.on(CustomerCreditLimitExceeded, handleCustomerCreditLimitExceeded)
.fallback(handleUnknownError)
}
}
function doSomething() {
throw new CustomerNotFound()
}
Test
yarn test