Skip to content

Commit

Permalink
return handler error
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsandavari committed Mar 20, 2023
1 parent 854fbc0 commit 15e4b92
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mediatr.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ func Send[TRequest any, TResponse any](ctx context.Context, request TRequest) (T
response, err := v()

if err != nil {
return *new(TResponse), errors.Wrap(err, "error handling request")
// error handling request
return *new(TResponse), err
}

return response.(TResponse), nil
} else {
res, err := handlerValue.Handle(ctx, request)
if err != nil {
return *new(TResponse), errors.Wrap(err, "error handling request")
// error handling request
return *new(TResponse), err
}

response = res
Expand Down
3 changes: 1 addition & 2 deletions mediatr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ func (t *mediatorTests) Test_Send_Should_Throw_Error_If_No_Handler_Registered()

func (t *mediatorTests) Test_Send_Should_Return_Error_If_Handler_Returns_Error() {
defer cleanup()
expectedErr := "error handling request"
handler3 := &RequestTestHandler3{}
errRegister := RegisterRequestHandler[*RequestTest2, *ResponseTest2](handler3)
if errRegister != nil {
t.Error(errRegister)
}
_, err := Send[*RequestTest2, *ResponseTest2](context.Background(), &RequestTest2{Data: "test"})
assert.Containsf(t, err.Error(), expectedErr, "expected error containing %q, got %s", expectedErr, err)
assert.NotNil(t, err)
}

func (t *mediatorTests) Test_Send_Should_Dispatch_Request_To_Handler_And_Get_Response_Without_Pipeline() {
Expand Down

0 comments on commit 15e4b92

Please sign in to comment.