fixes #2822: Post vote API: returns 200 for both success and failure; fixes bug with x-api-limit header
This commit is contained in:
@@ -47,7 +47,7 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
throttled = CurrentUser.user.token_bucket.throttled?
|
||||
headers["X-Api-Limit"] = CurrentUser.user.token_bucket.token_count
|
||||
headers["X-Api-Limit"] = CurrentUser.user.token_bucket.token_count.to_s
|
||||
|
||||
if throttled
|
||||
respond_to do |format|
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
class CommentVotesController < ApplicationController
|
||||
respond_to :js, :json, :xml
|
||||
before_filter :member_only
|
||||
skip_before_filter :api_check
|
||||
|
||||
def create
|
||||
@comment = Comment.find(params[:comment_id])
|
||||
@comment_vote = @comment.vote!(params[:score])
|
||||
respond_with(@comment_vote)
|
||||
rescue CommentVote::Error, ActiveRecord::RecordInvalid => x
|
||||
@error = x
|
||||
render status: 500
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -13,5 +16,6 @@ class CommentVotesController < ApplicationController
|
||||
@comment.unvote!(params[:score])
|
||||
rescue CommentVote::Error => x
|
||||
@error = x
|
||||
render status: 500
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,8 +5,9 @@ class PostVotesController < ApplicationController
|
||||
def create
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.vote!(params[:score])
|
||||
rescue PostVote::Error => x
|
||||
rescue PostVote::Error, ActiveRecord::RecordInvalid => x
|
||||
@error = x
|
||||
render status: 500
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -14,5 +15,6 @@ class PostVotesController < ApplicationController
|
||||
@post.unvote!
|
||||
rescue PostVote::Error => x
|
||||
@error = x
|
||||
render status: 500
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user