From 1216c249e8e6274cd2ea0eda3264bb41768817ea Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 24 Jan 2022 22:42:46 +0100 Subject: [PATCH] Return different responses for use case errors --- app/controllers/ajax_controller.rb | 12 ++++++++++++ lib/use_case/question/create.rb | 1 + 2 files changed, 13 insertions(+) diff --git a/app/controllers/ajax_controller.rb b/app/controllers/ajax_controller.rb index c9732555..5085ba00 100644 --- a/app/controllers/ajax_controller.rb +++ b/app/controllers/ajax_controller.rb @@ -20,6 +20,18 @@ class AjaxController < ApplicationController end end + rescue_from(Errors::Base) do |e| + Sentry.capture_exception(e) + + @response = { + success: false, + message: e.message, + status: e.code + } + + return_response + end + rescue_from(KeyError) do |e| Sentry.capture_exception(e) diff --git a/lib/use_case/question/create.rb b/lib/use_case/question/create.rb index f452725c..8a120865 100644 --- a/lib/use_case/question/create.rb +++ b/lib/use_case/question/create.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "use_case/base" +require "errors" module UseCase module Question