Skip to content

Commit

Permalink
feat: Create no_loan_update_exception in app_cont
Browse files Browse the repository at this point in the history
  • Loading branch information
MelTravelz committed Oct 29, 2023
1 parent b2f3e0c commit 683d415
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
class ApplicationController < ActionController::API
before_action :set_current_user
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
rescue_from NoPuzzlesException, with: :no_puzzles
rescue_from NoPuzzlesFoundException, with: :no_puzzles_found
rescue_from PuzzleNotAvailableException, with: :puzzle_not_available
rescue_from NoLoanUpdateException, with: :no_loan_update

def record_not_found(exception)
render json: ErrorSerializer.new(exception, 404).serializable_hash, status: :not_found # 404
end

def no_puzzles
error = NoPuzzlesException.new("No puzzles found in this area.")
def no_puzzles_found
error = NoPuzzlesFoundException.new("No puzzles found in this area.")
render json: ErrorSerializer.new(error, 404).serializable_hash, status: :not_found # 404
end

def puzzle_not_available
error = NoPuzzlesException.new("Puzzle is not available for loan.")
error = PuzzleNotAvailableException.new("Puzzle is not available for loan.")
render json: ErrorSerializer.new(error, 404).serializable_hash, status: :not_found # 404
end

def no_loan_update
error = NoLoanUpdateException.new("Unable to update loan.")
render json: ErrorSerializer.new(error, 404).serializable_hash, status: :not_found # 404
end

Expand All @@ -27,6 +33,6 @@ def set_current_user

# Note to self: Saving this to remember process that lead me to final version:
# def no_puzzles
# render status: :no_content, json: {} # 204
# render json: { error: "No puzzles found in this area." }, status: :not_found # 404
# render status: :no_content, json: {} # 204
# render json: { error: "No puzzles found in this area." }, status: :not_found # 404
# end
2 changes: 2 additions & 0 deletions app/exceptions/no_loan_update_exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class NoLoanUpdateException < StandardError
end

0 comments on commit 683d415

Please sign in to comment.