Skip to content

Commit

Permalink
Make ApplicationController error handlers and authentication callback…
Browse files Browse the repository at this point in the history
… private
  • Loading branch information
scottohara committed Nov 27, 2024
1 parent 5e20c54 commit 1db1a24
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class ApplicationController < ::ActionController::API
rescue_from ::ActiveRecord::RecordNotFound, with: :record_not_found
include ::ActionController::HttpAuthentication::Basic::ControllerMethods

def routing_error
render json: "Path #{params[:unmatched_route]} is not valid", status: :not_found
end

private

def authenticate_user
render plain: 'Invalid login and/or password', status: :unauthorized unless authenticate_with_http_basic do |username, password|
username.eql?(::ENV[:TVMANAGER_USERNAME.to_s]) && password.eql?(::ENV[:TVMANAGER_PASSWORD.to_s])
Expand All @@ -26,8 +32,4 @@ def record_invalid(exception)
def record_not_found(exception)
render json: exception.message, status: :not_found
end

def routing_error
render json: "Path #{params[:unmatched_route]} is not valid", status: :not_found
end
end

0 comments on commit 1db1a24

Please sign in to comment.