# frozen_string_literal: true require "securerandom" require "json" module MinatoErrorHandler class MinatoError < StandardError SERVER_ERROR = 500 attr_accessor :details, :caused_by, :request def code self.class.name end def message "An unknow error has occurred! See more details in caused_by field." end def status_code SERVER_ERROR end def unique_identfier @unique_identfier ||= SecureRandom.uuid end def serializable_attributes(methods) methods end def to_json(*_args) serialized_hash.to_json end def as_json serialized_hash.as_json end protected def serialized_hash methods = serializable_attributes(%i[caused_by code details message status_code unique_identfier]) data = {} methods.each do |method| data[method] = send(method) end data end end end