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