Skip to content

Commit

Permalink
upgrade gem
Browse files Browse the repository at this point in the history
  • Loading branch information
wendelfabianchinsamy committed May 10, 2024
1 parent 9298748 commit 314d134
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,28 @@ def transform_params
params.transform_keys! { |key| key.tr('-', '_') }
end

rescue_from *RESCUABLE_EXCEPTIONS do |exception|
status = case exception.class.to_s
when "CanCan::AccessDenied", "JWT::DecodeError","JWT::VerificationError" then 401
when "ActiveRecord::RecordNotFound", "AbstractController::ActionNotFound", "ActionController::RoutingError" then 404
when "ActiveRecord::RecordNotUnique" then 409
when "ActiveModel::ForbiddenAttributesError", "ActionController::ParameterMissing", "ActionController::UnpermittedParameters", "NoMethodError", "ActiveRecord::RecordInvalid", "JSON::ParserError" then 422
else 400
end

if status == 404
message = "The resource you are looking for doesn't exist."
elsif status == 401
message = "You are not authorized to access this resource."
elsif status == 406
message = "The content type is not recognized."
elsif status == 409
message = "The resource already exists."
else
message = exception.message
end
rescue_from(*RESCUABLE_EXCEPTIONS) do |exception|
status =
case exception.class.to_s
when "CanCan::AccessDenied", "JWT::DecodeError","JWT::VerificationError" then 401
when "ActiveRecord::RecordNotFound", "AbstractController::ActionNotFound", "ActionController::RoutingError" then 404
when "ActiveRecord::RecordNotUnique" then 409
when "ActiveModel::ForbiddenAttributesError", "ActionController::ParameterMissing", "ActionController::UnpermittedParameters", "NoMethodError", "ActiveRecord::RecordInvalid", "JSON::ParserError" then 422
else
400
end

if status == 404
message = "The resource you are looking for doesn't exist."
elsif status == 401
message = "You are not authorized to access this resource."
elsif status == 406
message = "The content type is not recognized."
elsif status == 409
message = "The resource already exists."
else
message = exception.message
end

render json: { errors: [{ status: status.to_s, title: message }] }.to_json, status: status
end
Expand Down

0 comments on commit 314d134

Please sign in to comment.