Module: Core::Service::ErrorHandling

Defined in:
app/api/core/service/error_handling.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/api/core/service/error_handling.rb', line 3

def self.registered(app) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  app.instance_eval do
    helpers Helpers

    error(
      ::IllegalOperation,
      ::Core::Service::Error,
      ActiveRecord::ActiveRecordError,
      ActiveModel::ValidationError,
      Aliquot::TagClash
    ) do
      buffer = [exception_thrown.message, exception_thrown.backtrace].join("\n")
      Rails.logger.error("API[error]: #{buffer}")
      exception_thrown.api_error(self)
    end
    error(StandardError) do
      buffer = [exception_thrown.message, exception_thrown.backtrace].join("\n")
      Rails.logger.error("API[error]: #{buffer}")
      general_error(501)
    end
  end
end