Sha256: 9817b672d681203b0de8e75d01606fca36ff5e672d4f57346878d236167828d5
Contents?: true
Size: 980 Bytes
Versions: 1
Compression:
Stored size: 980 Bytes
Contents
# frozen_string_literal: true require "securerandom" require "json" module MinatoErrorHandler class MinatoError < StandardError def initialize(details: {}, caused_by: nil, status_code: 500) @caused_by = caused_by @details = details @status_code = status_code super end def self.from_error(error) return error if error.is_a?(MinatoErrorHandler::MinatoError) new caused_by: error.cause end attr_reader :details, :status_code def message "An unknow error has occurred!" end def code self.class.name end def unique_identfier @unique_identfier || SecureRandom.uuid end def caused_by @caused_by || cause end def serialized_hash { message: message, code: code, unique_identfier: unique_identfier, details: details, caused_by: caused_by, status_code: status_code } end def to_json(*_args) serialized_hash.as_json end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
minato_error_handler-0.1.2 | lib/minato_error_handler/minato_error.rb |