From 0f2cbe8a5276cd9e81757b691c6bd28ebc953295 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:37:47 +0100 Subject: [PATCH] Fix API exception response handling For some reason when using `render text:` instead of `render json:` for this response, the status code being returned was 200 instead of the clearly explicitly defined 422 (:unprocessable_entity). I absolutely have no idea why! --- app/controllers/api/base_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 0de0d45d99..2641cdaf44 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -73,7 +73,7 @@ module Api end def error_during_processing(exception) - render(text: { exception: exception.message }.to_json, + render(json: { exception: exception.message }, status: :unprocessable_entity) && return end