commanded / commanded-audit-middleware

Command auditing middleware for Commanded CQRS/ES applications
MIT License
39 stars 17 forks source link

Error thrown before the start_time causes delta for end_time to fail #4

Open scott-wyatt opened 6 years ago

scott-wyatt commented 6 years ago

Error

1) test register user should fail when email address already taken and return error (Conduit.UsersTest)
     test/conduit/users/users_test.exs:69
     ** (FunctionClauseError) no function clause matching in Commanded.Middleware.Auditing.delta/1

     The following arguments were given to Commanded.Middleware.Auditing.delta/1:

%Commanded.Middleware.Pipeline{assigns: %{error: :validation_failure, error_reason: %{email: ["has already been taken"]}}, 
...

To Reproduce

Add commanded-audit-middleware to Conduit, and then run mix test.

Suggested Solution

Pattern Matching for delta

for when a delta does not yet have a start_time and error is already thrown.

slashdotdash commented 6 years ago

The auditing middleware needs to be the first middleware defined in your router to ensure it gets executed before any other middleware can halt command dispatch.

Probably worth doing either or both of the following:

Happy to accept a PR to help fix the issue.