diff --git a/Gemfile.lock b/Gemfile.lock index a459eb89b..d3f484471 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/WGBH-MLA/sony_ci_api_rewrite.git - revision: 9a668ab0649aa6bb03aa259de0cf1687e52e86fb + revision: 4db6435e97b1b3abef0cbceae38820d450935c12 branch: v0.1 specs: sony_ci_api (0.1.0) diff --git a/app/controllers/sony_ci/api_controller.rb b/app/controllers/sony_ci/api_controller.rb index 5680f88ff..cff996556 100644 --- a/app/controllers/sony_ci/api_controller.rb +++ b/app/controllers/sony_ci/api_controller.rb @@ -2,7 +2,8 @@ module SonyCi class APIController < ::APIController - rescue_from StandardError, with: :default_error + rescue_from StandardError, with: :handle_default_error + rescue_from SonyCiApi::Error, with: :handle_sony_ci_api_error def find_media result = sony_ci_api.workspace_search( @@ -38,11 +39,13 @@ def permitted_params end # Default error handler. Respond with JSON error and 500 - def default_error(e) - # If the error is a SonyCiApi::Error, it should have an http_status, - # if so, use it. Else default to 500. - status = e.respond_to?(:http_status) ? e.http_status : 500 - render json: { error: e.class.to_s, error_message: e.message }, status: status + def default_error(error) + render json: { error: error.class.to_s, error_message: error.message }, status: status + end + + # Error handler for SonyCiApi::Error and subclasses thereof. + def handle_sony_ci_api_error(error) + render json: error.to_h, status: error.http_status end end end