# frozen_string_literal: true require "securerandom" require "json" module MinatoErrorHandler class MinatoError < StandardError attr_accessor :details, :caused_by, :request def message raise_method_not_implemented_error __method__ end def status_code raise_method_not_implemented_error __method__ end def serializable_methods raise_method_not_implemented_error __method__ end def code self.class.name end def unique_identfier @unique_identfier ||= SecureRandom.uuid end def to_json(*_args) serialized_hash.to_json end def as_json serialized_hash.as_json end protected def default_serializable_methods %i[caused_by code details message request status_code unique_identfier] end def serialized_hash data = {} serializable_methods.each do |method| data[method] = send(method) end data end def raise_method_not_implemented_error(method_name) raise "You must define \"#{method_name}\" in your concrete class." end end end