Sha256: 3ca7d987d3d08144b87d800b051524b8f2845ce56c8a2c3aade62982ddde22e9

Contents?: true

Size: 547 Bytes

Versions: 3

Compression:

Stored size: 547 Bytes

Contents

# frozen_string_literal: true

require "minato_logger"

module MinatoErrorHandler
  module ErrorHandler
    extend ActiveSupport::Concern

    included do
      rescue_from StandardError, with: :handle
    end

    private

    def handle(exception)
      error = MinatoErrorHandler::MinatoError.from_error(exception)
      report_error(error)
      render json: { errors: [error.to_json] }, status: error.status_code
    end

    def report_error(error)
      logger = MinatoLogger::Logger.new
      logger.error(error.to_json)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
minato_error_handler-0.1.2 lib/minato_error_handler/error_handler.rb
minato_error_handler-0.1.1 lib/minato_error_handler/error_handler.rb
minato_error_handler-0.1.0 lib/minato_error_handler/error_handler.rb