Sha256: b4ed9ffec2024096e1968024175ff264ee1020cb2fd7f4e4ed5f023d9be1463e
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
module Salestation module Web module ErrorMapper ERROR_TO_RESPONSE = { App::Errors::InvalidInput => -> (error) { Responses::UnprocessableEntityFromSchemaErrors.create(error) }, App::Errors::DependencyCurrentlyUnavailable => -> (error) { Responses::ServiceUnavailable.new( message: error.message, debug_message: "Please try again later" ) }, App::Errors::RequestedResourceNotFound => -> (error) { Responses::NotFound.new(message: "Resource not found") }, App::Errors::Forbidden => -> (error) { Responses::Forbidden.new(message: error.message) } }.freeze def self.map -> (error) do _, error_mapper = ERROR_TO_RESPONSE .find {|error_type, _| error.kind_of?(error_type) } # Interpret a Failure from the application layer as Success in the web # layer. Even if the domain specific operation failed, the web layer is # still able to successfully produce a well-formed response. if error_mapper Deterministic::Result::Success(error_mapper.call(error)) elsif error.is_a?(Hash) Deterministic::Result::Success(Responses::InternalError.new(error)) else raise "Unknown error #{error.class.name}" end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
salestation-0.0.6 | lib/salestation/web/error_mapper.rb |
salestation-0.0.5 | lib/salestation/web/error_mapper.rb |