From c0be03dcb61e04d00046696ab5817dcb3377b63f Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 21 Dec 2022 23:28:54 -0800 Subject: [PATCH] Finish migrating ApiController error methods --- app/blueprints/api/v1/error_blueprint.rb | 4 ++++ app/controllers/api/v1/api_controller.rb | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/blueprints/api/v1/error_blueprint.rb b/app/blueprints/api/v1/error_blueprint.rb index 92a9580..78a431a 100644 --- a/app/blueprints/api/v1/error_blueprint.rb +++ b/app/blueprints/api/v1/error_blueprint.rb @@ -10,6 +10,10 @@ module Api field :errors, if: ->(_field_name, _error, options) { options.key?(:errors) } do |_, options| options[:errors] end + + field :errors, if: ->(_field_name, _error, options) { options.key?(:exception) } do |_, options| + options[:exception] + end end end end diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index 4a14f31..a1ae703 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -61,8 +61,8 @@ module Api end def render_unprocessable_entity_response(exception) - @exception = exception - render action: 'errors', status: :unprocessable_entity + render json: ErrorBlueprint.render_as_json(nil, exception: exception), + status: :unprocessable_entity end def render_validation_error_response(object) @@ -78,7 +78,8 @@ module Api end def render_unauthorized_response - render action: 'errors', status: :unauthorized + render json: ErrorBlueprint.render_as_json(nil), + status: :unauthorized end private