-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Rescue state machine exception from api base controller #3520
Rescue state machine exception from api base controller #3520
Conversation
986b485
to
22c8e18
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamuelMartini thanks for this PR 🎉
The fix looks good, but I left a note for possible improvement.
22c8e18
to
6b76ec6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Samuel!
Dismissing approval, since I found something to discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found a possible issue with current code. Let me know!
6b76ec6
to
7737e6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can also add some specs for other resources' controllers that have state machines? Just to be really sure it's working with any of them.
@@ -1,4 +0,0 @@ | |||
# frozen_string_literal: true | |||
|
|||
json.error(I18n.t(:could_not_transition, scope: "spree.api.order")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe someone is using this template in their store, we should keep it, print a deprecation warning and render the generic partial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can also add some specs for other resources' controllers that have state machines? Just to be really sure it's working with any of them.
I could not find any other controller which raise an exception because of the failed state machine transition.
There are controllers that prevent any exception by controlling the flow:
return_authorization#cancel
They also return a different message so it will be a breaking change to make them use the generic error message.
Added deprecation for order error messages:
https://github.com/solidusio/solidus/pull/3520/files#diff-72139884662b996fcc462020939b7807R195
7737e6c
to
85538cd
Compare
api/app/views/spree/api/orders/could_not_transition.json.jbuilder
Outdated
Show resolved
Hide resolved
54e88e7
to
faa487d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question on how the deprecation has been implemented, maybe I'm missing something. Thanks Samuel!
@SamuelMartini if you have time, could you please finalize this by addressing @kennyadsl's comment? It would be great to get this into 2.11 so we can switch to the new behavior in 3.0! |
4eaa001
to
3121604
Compare
3121604
to
5cca7c1
Compare
The rescue is moved on Spree::Api::BaseController so that it can be inherited from those controllers that deal with state machine transition. This commit also adds a test to ensure OrdersController#cancel does not return 500 when trying to transition to `cancel` an order that is not completed. When an order is not completed cannot be transitioned. When called in OrdersController#cancel through `canceled_by` the state machine exception result in a 500 error.
Remove state machine exception rescue as it is now rescued from Api/BaseController
Authorization already happen on the first line after the method definition
5cca7c1
to
e51fe03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Samuel and Daniele!
Description
When an order is not completed cannot be transitioned via
cancel!
OrdersController#cancel
call@order.cancel!
throughcanceled_by
: the state machineexception results in a 500 error when the action is called with a not completed order.
Pr changes:
StateMachines::InvalidTransition
exception from theBaseController
returning the default json response and 422 status.StateMachines::InvalidTransition
from Api/CheckoutsController. Note that this change remove the log message from the update action when the state machine raise an exception. However the invaid_transition method has an explicit message that should work:The first string in the above image is the removed log message. The last string is what is logged in `invalid_transition`.
next
action.Checklist: