Skip to content

Commit

Permalink
Merge pull request #15 from Clarilab/extend-event-bus-error
Browse files Browse the repository at this point in the history
feat: extend the event bus error
  • Loading branch information
nicoandrewss authored Dec 12, 2023
2 parents 235d14f + f0645b5 commit 0ac57d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/Clarilab/clarimq"
eh "github.com/looplab/eventhorizon"
)

// ErrCouldNotBeRouted is returned when a mandatory message could not be routed.
Expand Down Expand Up @@ -36,3 +37,10 @@ func (e *RecoveryFailedError) Error() string {

return str
}

// EventBusError is an async error containing the error returned from a handler and the event that it happened on.
// Its a wrapper around the eventhorizon.EventBusError with extra information about the handler.
type EventBusError struct {
eh.EventBusError
HandlerType eh.EventHandlerType
}
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (b *EventBus) returnHandler(rtn clarimq.Return) {
func (b *EventBus) sendErrToErrChannel(ctx context.Context, err error, h eh.EventHandler, event eh.Event) {
err = fmt.Errorf("could not handle event (%s): %w", h.HandlerType(), err)
select {
case b.errCh <- &eh.EventBusError{Err: err, Ctx: ctx, Event: event}:
case b.errCh <- &EventBusError{eh.EventBusError{Err: err, Ctx: ctx, Event: event}, h.HandlerType()}:
default:
b.logger.logError("eventhorizon: missed error in RabbitMQ event bus", "error", err)
}
Expand Down

0 comments on commit 0ac57d0

Please sign in to comment.