Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always pass the new order number on unreturned exchange failures #388

Merged
merged 3 commits into from
Dec 23, 2015

Conversation

magnusvk
Copy link
Contributor

Currently, anything that's not specifically a ChargeFailure will not
include the new order number. That's a pity, because something like an
out of stock error shows up as an exception that is not a
ChargeFailure and then it's really hard to even find the new error.

This always makes the new order available to the outside so that we
don't have to specifically read it from the exception.

Currently, anything that's not specifically a `ChargeFailure` will not
include the new order number. That's a pity, because something like an
out of stock error shows up as an exception that is not a
`ChargeFailure` and then it's really hard to even find the new error.

This always makes the new order available to the outside so that we
don't have to specifically read it from the exception.
@@ -53,12 +53,12 @@ def charge_for_items

end

private

def new_order
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should get its own special unit test now lol

@magnusvk
Copy link
Contributor Author

Jordan, I think you are right. Updated.

@@ -19,6 +19,8 @@ def initialize(shipment, return_items)
end

def charge_for_items
self.new_order = Spree::Order.create!(exchange_order_attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just do @new_order = ..., but this is a cool style!

@jhawthorn
Copy link
Contributor

looks okay

@jordan-brough
Copy link
Contributor

👍

@@ -20,12 +20,13 @@ namespace :exchanges do
begin
item_charger.charge_for_items
rescue Spree::UnreturnedItemCharger::ChargeFailure => e
failure = {message: e.message, new_order: e.new_order.try(:number)}
failure = { message: e.message }
rescue Exception => e
Copy link
Member

Choose a reason for hiding this comment

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

While you're here, if you could get rid of this, I'd really appreciate it.

Instead of

rescue Exception => e

just

rescue => e

Rescuing Exception will rescue syntax errors, signal exceptions and such. Things that you shouldn't be rescuing unless you're re-raising them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point; done.

@magnusvk
Copy link
Contributor Author

@jhawthorn good to merge?

@jhawthorn
Copy link
Contributor

lgtm 👍

failure = {message: e.message, new_order: e.new_order.try(:number)}
rescue Exception => e
failure = {message: "#{e.class}: #{e.message}"}
failure = { message: e.message }
Copy link
Contributor

Choose a reason for hiding this comment

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

We can now just collapse this into the rescue => e right?

@cbrunsdon
Copy link
Contributor

I would have prefered we return new_order from charge_for_items to make the API more explicit, but not enough to change anything. I'd probably want to wrap it in some kind of message back rather than just returning it, anyway.

Are we just waiting on the re-raise of the exception to finish this one off?

@magnusvk
Copy link
Contributor Author

Reading through this again, I would like to merge this PR as is. We always talk about keeping the surface area of changes as low as we can. Well, this is the minimal change: Always pass the new order. If we want to change the way we handle unexpected exceptions that's cool with me but I'd like to address it in a separate PR. I wouldn't even collapse the two rescues as that would change behavior in that it would change the message.

@jordan-brough @cbrunsdon Is that ok with you?

@jordan-brough
Copy link
Contributor

👍

@cbrunsdon
Copy link
Contributor

Sure, 👍 by me

athal7 pushed a commit that referenced this pull request Dec 23, 2015
Always pass the new order number on unreturned exchange failures
@athal7 athal7 merged commit 7f971e1 into solidusio:master Dec 23, 2015
@athal7 athal7 deleted the always-pass-new-order branch December 23, 2015 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants