Handling Errors
Error handling is critical for building robust workflows that can handle non-happy paths. It allows for short-circuiting operations and following an alternative path in the presence of expected but unusual situations. It can be seen as a more convenient alternative to Forks.
Errors defined and handled should be domain errors and not technical ones. Domain errors represent business-level exceptions that are meaningful in your workflow context, rather than implementation-specific exceptions like network failures or timeouts.
val doThings: WIO[MyState, MyError, Nothing] =
WIO.pure.error(MyError()).autoNamed
val handleThatNastyError: WIO[(MyState, MyError), Nothing, MyState] =
WIO.pure(MyState(1)).autoNamed
val errorHandled: WIO[MyState, Nothing, MyState] =
doThings.handleErrorWith(handleThatNastyError)
Rendering Outputs
- Flowchart
- BPMN
- Model
{
"base" : {
"meta" : {
"name" : "Do Things",
"error" : {
"name" : "My Error"
}
},
"_type" : "Pure"
},
"handler" : {
"meta" : {
"name" : "Handle That Nasty Error",
"error" : null
},
"_type" : "Pure"
},
"meta" : {
"newErrorMeta" : null,
"handledErrorMeta" : {
"name" : "My Error"
}
},
"_type" : "HandleError"
}