Sha256: e91d7ed0296e912402c8e5fb32512f5f82c2157c9eae444f105ce171d2979c64
Contents?: true
Size: 860 Bytes
Versions: 1
Compression:
Stored size: 860 Bytes
Contents
# frozen_string_literal: true # require "minato_logger" module MinatoErrorHandler module ErrorHandler extend ActiveSupport::Concern attr_accessor :default_error_class included do rescue_from StandardError, with: :handle end private def handle(exception) error = parse_error(exception) report_error(error) render json: { errors: [error.as_json] }, status: error.status_code end def parse_error(error) return error if error.is_a?(MinatoErrorHandler::MinatoError) error_class = default_error_class || MinatoErrorHandler::MinatoError minato_error = error_class.new minato_error.caused_by = error.full_message minato_error.set_backtrace(error.backtrace) minato_error end def report_error(error) Rails.logger.error(error.as_json) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
minato_error_handler-0.1.2.pre.1 | lib/minato_error_handler/error_handler.rb |