Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Improve error message for missing store items #75

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,17 @@ def generate_payment_response(payment_intent)
"👚" => 2500,
}

def price_lookup(product)
price = EMOJI_STORE[product]
raise "Can't find price for %s (%s)" % [product, product.ord.to_s(16)] if price.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a default price for something instead of raising an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to know why it’s happening instead of silently ignoring it: The Emoji store items should line up between the server and the client, so breakage could indicate a problem with Unicode parsing or something.

return price
end

def calculate_price(products, shipping)
amount = 1099 # Default amount.

if products
amount = products.reduce(0) { | sum, product | sum + EMOJI_STORE[product] }
amount = products.reduce(0) { | sum, product | sum + price_lookup(product) }
end

if shipping
Expand Down