mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
add error handling to routing
This commit is contained in:
16
router.go
16
router.go
@@ -8,6 +8,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RoutingError struct {
|
||||||
|
Index int
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
contextCancel context.CancelFunc
|
contextCancel context.CancelFunc
|
||||||
Context context.Context
|
Context context.Context
|
||||||
@@ -129,15 +134,24 @@ func (r *Router) Stop() {
|
|||||||
r.contextCancel()
|
r.contextCancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) HandleInput(sourceId string, payload any) {
|
func (r *Router) HandleInput(sourceId string, payload any) []RoutingError {
|
||||||
|
var routingErrors []RoutingError
|
||||||
for routeIndex, route := range r.RouteInstances {
|
for routeIndex, route := range r.RouteInstances {
|
||||||
if route.Input == sourceId {
|
if route.Input == sourceId {
|
||||||
err := route.HandleInput(sourceId, payload)
|
err := route.HandleInput(sourceId, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if routingErrors == nil {
|
||||||
|
routingErrors = []RoutingError{}
|
||||||
|
}
|
||||||
|
routingErrors = append(routingErrors, RoutingError{
|
||||||
|
Index: routeIndex,
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
slog.Error("router unable to route input", "route", routeIndex, "source", sourceId, "error", err)
|
slog.Error("router unable to route input", "route", routeIndex, "source", sourceId, "error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return routingErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) HandleOutput(destinationId string, payload any) error {
|
func (r *Router) HandleOutput(destinationId string, payload any) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user