Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "ostruct"

class ApplicationController < ActionController::Base
include Pagy::Backend
include SessionsHelper
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/black_candy/errors.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down