lib/mihari/errors.rb in mihari-7.0.4 vs lib/mihari/errors.rb in mihari-7.0.5

- old
+ new

@@ -1,29 +1,47 @@ # frozen_string_literal: true +require "http" + module Mihari class Error < StandardError; end class ValueError < Error; end - class RetryableError < Error; end - class ConfigurationError < Error; end - class IntegrityError < Error; end + class ResponseError < Error; end - # errors for HTTP interactions - class HTTPError < Error; end + class AnalyzerError < Error + # @return [StandardException, nil] + attr_reader :cause - class NetworkError < HTTPError; end + # + # @param [String] msg + # @param [String] analyzer + # @param [StandardException, nil] cause + # + def initialize(msg, analyzer, cause: nil) + super("#{msg} (from #{analyzer})") - class TimeoutError < HTTPError; end + @cause = cause + set_backtrace(cause.backtrace) if cause + end + def detail + return nil unless cause.respond_to?(:detail) + + cause.detail + end + end + + class IntegrityError < Error; end + # # HTTP status code error # - class StatusCodeError < HTTPError + class StatusCodeError < ::HTTP::Error # @return [Integer] attr_reader :status_code # @return [String, nil] attr_reader :body @@ -37,10 +55,14 @@ super(msg) @status_code = status_code @body = body end + + def detail + { status_code: status_code, body: body } + end end # # (dry-schema) Schema validation error # @@ -53,8 +75,12 @@ # def initialize(msg, errors) super(msg) @errors = errors + end + + def detail + errors.to_h end end end