Skip to content

Commit

Permalink
Handles SonyCiApi errors
Browse files Browse the repository at this point in the history
Updates sony_ci_api gem with refactored error handling.
  • Loading branch information
afred committed Aug 19, 2021
1 parent d2bce49 commit b7a36b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
15 changes: 9 additions & 6 deletions app/controllers/sony_ci/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

0 comments on commit b7a36b1

Please sign in to comment.