Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass instance of the interaction to InvalidInteractionError class #477

Merged
merged 5 commits into from Feb 14, 2020
Merged

Pass instance of the interaction to InvalidInteractionError class #477

merged 5 commits into from Feb 14, 2020

Conversation

ivdma
Copy link
Contributor

@ivdma ivdma commented Jan 15, 2020

Allows an ActiveInteraction::InvalidInteractionError to behave in a similar way as ActiveRecord::RecordInvalid which exposes the failed #record.

ActiveInteraction::InvalidInteractionError exposes #interaction attribute which includes failing interaction. This feature allows for better inspection of why interaction failed and therefore makes feedback to consumers of interaction errors more flexible.

Take for example a Rails controller action which might need to be rescued and whose error details need to be passed to the frontend.

class FooController < ApplicationController
  rescue_from ActiveInteraction::InvalidInteractionError do |exception|
    render json: { errors: exception.interaction.errors.details }, status: :unprocessable_entity
  end

  def update
    result = Foos::Update.run! permitted_params

    render json: result, serializer: FooSerializer, status: :updated
  end
end

mdwagner and others added 4 commits October 30, 2019 18:17
Add Note in Readme about Interface not requiring methods
Skipping Style/IfUnlessModifier as it is current state of this code.
@ivdma ivdma changed the title pass self as an argument to InvalitInteractionError class Pass instance of the interaction to InvalitInteractionError class Jan 15, 2020
@ivdma ivdma marked this pull request as ready for review January 15, 2020 15:47
@ivdma ivdma changed the title Pass instance of the interaction to InvalitInteractionError class Pass instance of the interaction to InvalidInteractionError class Jan 15, 2020
@ivdma
Copy link
Contributor Author

ivdma commented Feb 3, 2020

Hello @AaronLasseigne, anything I can do to help you with this PR?

@AaronLasseigne
Copy link
Owner

No, I just need to get some time to take a good look at it.

@AaronLasseigne AaronLasseigne changed the base branch from master to v3.8.0 February 14, 2020 20:12
@AaronLasseigne AaronLasseigne merged commit 768ae4b into AaronLasseigne:v3.8.0 Feb 14, 2020
@cokara
Copy link

cokara commented Apr 3, 2020

We should probably have made the interaction parameter in the initializer default to nil and only bubble up the errors if the interaction is supplied.
This is a breaking change since calling InvalidInteractionError.new without any parameter now blows up. :-)

@AaronLasseigne
Copy link
Owner

Thanks for the note. I've put out a fix (3.8.1).

@cokara
Copy link

cokara commented Apr 4, 2020

Thanks for the note. I've put out a fix (3.8.1).

You're welcome! I appreciate the quick response too. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants