Skip to content

Commit

Permalink
HYC-1810 - MissingTemplate error for info.json requests (#1048)
Browse files Browse the repository at this point in the history
* Set formats for error pages

* Add render_json_response method from included class which does not appear to be available

* HYC-1813 - Send UnknownFormat errors to 404 page, and specify html format for most errors
  • Loading branch information
bbpennel authored Nov 13, 2023
1 parent f5ef72f commit c5fcf33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@ class ApplicationController < ActionController::Base
rescue_from Hyrax::ObjectNotFoundError, with: :render_404
rescue_from ActiveFedora::ObjectNotFoundError, with: :render_404
rescue_from ActionController::InvalidAuthenticityToken, with: :render_401
rescue_from ActionController::UnknownFormat, with: :render_404

protected

def render_400
render 'errors/not_found', status: 400
render 'errors/not_found', status: 400, formats: :html
end

def render_401
render 'errors/not_found', status: 401
render 'errors/not_found', status: 401, formats: :html
end

def render_riiif_404
render_json_response(response_type: :not_found)
end

def render_json_response(response_type: :success, message: nil, options: {})
json_body = Hyrax::API.generate_response_body(response_type: response_type, message: message, options: options)
render json: json_body, status: response_type
end

def render_404
render 'errors/not_found', status: 404
render 'errors/not_found', status: 404, formats: :html
end

def render_500
render 'errors/internal_server_error', status: 500
render 'errors/internal_server_error', status: 500, formats: :html
end

# Error caught in catalogController
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true
class ErrorsController < ApplicationController
def not_found
render nothing: true, status: 404
render nothing: true, status: 404, formats: :html
end

def internal_server_error
render nothing: true, status: 500
render nothing: true, status: 500, formats: :html
end
end

0 comments on commit c5fcf33

Please sign in to comment.