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

Dry::Matcher::NonExhaustiveMatchError #3

Open
Coeur2Boeuf opened this issue Feb 14, 2017 · 2 comments
Open

Dry::Matcher::NonExhaustiveMatchError #3

Coeur2Boeuf opened this issue Feb 14, 2017 · 2 comments

Comments

@Coeur2Boeuf
Copy link

Hi,

Due to reproduce demo (and example) and use 2 cases (success & unauthenticated)

Trailblazer::Endpoint.new.(result) do |m|
m.success { |result| redirect_to comments_url }
m.unauthenticated { |result| 401 }
end

Result => Dry::Matcher::NonExhaustiveMatchError in CommentsController#create

@KonstantinKo
Copy link

I noticed the same thing. You always have to provide the entire set of endpoints, so I find myself writing a lot of empty endpoint definitions for cases that cannot happen. I'd prefer it if it would either fall back to the default (rails) endpoints or just throw an exception when there is no definition for an endpoint that turned out to be needed after all.

@onemanstartup
Copy link

onemanstartup commented May 15, 2017

Ok, I figure out how to do it pretty easily.
I added rescue to this error onemanstartup@8818a68
But to avoid double render you must return render in your custom handlers.
Right now, i don't a better way to merge 2 blocks without NonExhaustiveMatch error

  def update
    endpoint User::Update do |m|
      m.updated do |result|
        bypass_sign_in(current_user) if result.success? && params[:user][:password]
        return render json: result['representer.model.class'].new(result['model']), status: 200
      end
    end
  end

UPDATE: It doesn't run common handlers if block is not present, so you just need add condition to run only common handlers if block is present

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

No branches or pull requests

3 participants