Sha256: 7ac532fa4a6bd5c74438c7bd2a0c19efbc374d643a3d46239aef824ebdf93ca8

Contents?: true

Size: 1.4 KB

Versions: 13

Compression:

Stored size: 1.4 KB

Contents

module Fiona7
  class ErrorHandler
    HANDLED_ERRORS = [
      Reactor::Cm::MissingCredentials,
      Reactor::Cm::XmlRequestError,
      Reactor::NoWorkingVersion,
      Reactor::NotPermitted,
      Reactor::AlreadyReleased,
      Fiona7::TypeSystemError
    ]

    attr_accessor :error, :locale

    def initialize(error, locale = Scrivito::Configuration.ui_locale || I18n.locale)
      self.error  = error
      self.locale = locale
    end

    def sdk_error
      Scrivito::ApplicationError.new(self.processed_message)
    end

    def api_error
      self.processed_message
    end

    def processed_message
      Rails.logger.error(self.error.inspect)
      Rails.logger.error(self.error.backtrace.join("\n"))

      case self.error
      when Reactor::Cm::XmlRequestError
        self.error.message.gsub(/\[[0-9]+\] /, '')
      when Reactor::Cm::MissingCredentials
        I18n.t(:"fiona7.errors.missing_credentials", locale: self.locale)
      when Reactor::NoWorkingVersion
        I18n.t(:"fiona7.errors.no_working_version", locale: self.locale)
      when Reactor::NotPermitted
        I18n.t(:"fiona7.errors.not_permitted", locale: self.locale)
      when Reactor::AlreadyReleased
        I18n.t(:"fiona7.errors.already_released", locale: self.locale)
      when Fiona7::TypeSystemError
        I18n.t(:"fiona7.errors.type_system", locale: self.locale)
      else
        self.error.message
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.5.5.1 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.5.5.0 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.5.4.1 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.5.4.0 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.5.3.1 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.4.3.0 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.3.2.0 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.3.2.0.pre.beta1 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.2.1.0.pre.beta1 lib/fiona7/controllers/rest_api/error_handler.rb
infopark_fiona7-1.5.2.0.0 lib/fiona7/controllers/rest_api/error_handler.rb