Updated EmptyController to have protections and error responses

• Updated:
- EmptyController to have protections and error responses
This commit is contained in:
mgabdev 2020-11-09 12:10:11 -06:00
parent 297fac5d21
commit 83006eed39
1 changed files with 32 additions and 0 deletions

View File

@ -2,6 +2,38 @@
class EmptyController < ActionController::Base
include RateLimitHeaders
protect_from_forgery with: :null_session
rescue_from ActiveRecord::RecordInvalid, GabSocial::ValidationError do |e|
render json: { error: e.to_s }, status: 422
end
rescue_from ActiveRecord::RecordNotFound do
render json: { error: 'Record not found' }, status: 404
end
rescue_from HTTP::Error, GabSocial::UnexpectedResponseError do
render json: { error: 'Remote data could not be fetched' }, status: 503
end
rescue_from OpenSSL::SSL::SSLError do
render json: { error: 'Remote SSL certificate could not be verified' }, status: 503
end
rescue_from GabSocial::NotPermittedError do
render json: { error: 'This action is not allowed' }, status: 403
end
def doorkeeper_unauthorized_render_options(error: nil)
{ json: { error: (error.try(:description) || 'Not authorized') } }
end
def doorkeeper_forbidden_render_options(*)
{ json: { error: 'This action is outside the authorized scopes' } }
end
protected
def current_user