diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 28e6380f..8045201d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "ostruct" - class ApplicationController < ActionController::Base include Pagy::Backend include SessionsHelper @@ -36,7 +34,7 @@ class ApplicationController < ActionController::Base rescue_from ActiveRecord::RecordNotFound do |error| respond_to do |format| - format.json { render_json_error(OpenStruct.new(type: "RecordNotFound", message: error.message), :not_found) } + format.json { render_json_error(BlackCandy::CustomError.new("RecordNotFound", error.message), :not_found) } format.html { render template: "errors/not_found", layout: "plain", status: :not_found } end end diff --git a/lib/black_candy/errors.rb b/lib/black_candy/errors.rb index 0038283a..988eb5d7 100644 --- a/lib/black_candy/errors.rb +++ b/lib/black_candy/errors.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true module BlackCandy + CustomError = Data.define(:type, :message) + class BaseError < StandardError def type self.class.name.split("::").last