Open Coeur2Boeuf opened 7 years ago
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.
Ok, I figure out how to do it pretty easily. I added rescue to this error https://github.com/onemanstartup/trailblazer-endpoint/commit/8818a685a1a2c2a98087d01e525a9f10d83674a1 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
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