-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Add error class to checkout endpoint response #47489
base: trunk
Are you sure you want to change the base?
Conversation
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
Hi @vedanshujain, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
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 reviewed these changes along with the changes proposed in Automattic/woocommerce-payments#8824 and confirmed that it helps address the issue in WooPayments/WooPay.
Requesting changes due to an out-of-scope variable issue that this could run into, although I haven't been able to replicate it myself.
Let's also get a review from the core devs, team Proton.
@@ -85,7 +85,13 @@ private function process_payment( \WP_REST_Request $request, PaymentResult $paym | |||
throw new RouteException( 'woocommerce_rest_checkout_invalid_payment_result', __( 'Invalid payment result received from payment method.', 'woocommerce' ), 500 ); | |||
} | |||
} catch ( \Exception $e ) { | |||
throw new RouteException( 'woocommerce_rest_checkout_process_payment_error', esc_html( $e->getMessage() ), 400 ); | |||
if ( $e->getPrevious() ) { |
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.
$additional_data
is defined inside the branch. Line 94 will error out if the exception doesn't go into the condition, as the variable will be undefined.
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.
Thank you for catching that! Fixed here 86d1eef
963ec4c
to
86d1eef
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.
@hsingyuc this will send out the class name in the API response, which is usually an internal detail. Are we sure we want this, instead of just logging this or only sending out when Constants::is_true( 'WP_DEBUG' )
is true.
Additionally, the status code should be 500
Closing and reopening the PR to trigger CI. |
@vedanshujain Thank you for the review! We'll use the response in WooPay, so we can't just log it or be on
This is the error code that was already there. Are you sure we should change it? This normally happens because of bad input and not because of a server error. |
I see, maybe we can send in some sort of error code, as prefix to the error message. So something like
Ah ok, in this case 400 is fine |
I don't quite understand where we should add the prefix, can you expand on what you mean? Do you want this added to the exception message? This is shown to customers, so I'm not sure we should add it there. The issue we are trying to solve is from this generic error message and error code. So, we updated Exceptions to more unique exception types and we pass this as the previous exception so we have data to be able to figure out where the error is coming from exactly. We need to be careful to not change the original exception because this is shown to customers. |
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.
LGTM and tests well, note that we are still discussing whether it's ok to expose the error class names. There's also a lint workflow that's failing, but other than these two things we should be good to merge.
Also updated testing instructions to remove |
e75c6b9
to
7027662
Compare
Submission Review Guidelines:
Changes proposed in this Pull Request:
I chose to use
previous
inside the additional data because we can't guarantee what interfaces we are getting on thrown exceptions fromprocess_payment
.Alternative example that won't work::
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
{YOUR_DOMAIN}/wp-json/wc/store/v1/cart/add-item
{YOUR_DOMAIN}/wp-json/wc/store/v1/checkout
Changelog entry
Significance
Type
Message
Add previous error class to checkout endpoint response
Comment