comment votes: fix error handling.

Return the comment itself and a standard error response on failure.
This commit is contained in:
evazion
2019-08-19 16:57:38 -05:00
parent b8450671f2
commit 782d9f3d61
8 changed files with 19 additions and 48 deletions

View File

@@ -2,20 +2,17 @@ class CommentVotesController < ApplicationController
respond_to :js, :json, :xml
before_action :member_only
skip_before_action :api_check
rescue_with CommentVote::Error, ActiveRecord::RecordInvalid, status: 422
def create
@comment = Comment.find(params[:comment_id])
@comment_vote = @comment.vote!(params[:score])
rescue CommentVote::Error, ActiveRecord::RecordInvalid => x
@error = x
render status: 422
respond_with(@comment)
end
def destroy
@comment = Comment.find(params[:comment_id])
@comment.unvote!
rescue CommentVote::Error => x
@error = x
render status: 422
respond_with(@comment)
end
end