-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Code cleanup Update Paypal invokeApi to only throw exceptions. #16072
Conversation
(Standard links)
|
test this please |
@mattwire @artfulrobot - in reviewing Rich's last change I concluded we should do this - since it makes no sense to return an error for a curl error & throw an exception for a processor error - esp given the former is almost always converted to the latter |
CRM/Core/Payment/PayPalImpl.php
Outdated
curl_error($ch) | ||
); | ||
return $e; | ||
throw new PaymentProcessorException(curl_errno($ch)); |
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.
Wouldn't we want to include curl_error($ch)
output as well as error no?
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.
Yeah I guess it could be
throw new PaymentProcessorException(curl_error($ch), curl_errno($ch));
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.
updated per ^^
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'd be tempted to prefix it with "Network error: " too, as Curl's errors are not very user friendly.
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.
OK - the errno is now duplicated because I have a feeling just putting it as error_code it might get swallowed & more info rather than less is probably helpful if there is a curl error
(CiviCRM Review Template DEL-1.2)
|
d1dbd71
to
94ce42c
Compare
Code quality ( Looks good to me, thanks @eileenmcnaughton |
Currently invokeAPI will return an error for a curl function and throw a processorException for an outcome other than success. In just about every instance where it is called the Core_Error is converted into an exception anyway - this can all be cleaned up as a follow up. The exceptions are doQuery - called by doPayment doDirectPayment - this is called by doPayment which converts it into an exception. Calling doDirectPayment directly was deprecated in 4.6 createRecurringPayments - called by doExpressCheckout which in already throws exceptions in other scenarios, updateSubscriptionBillingInfo - we can update the one place that calls this in core as a follow up like civicrm#15676 However, note that an exception was already thrown in all these places in the more common error scenario of the action not succeeding as opposed to the rare curl error scenario Follow ons to consider 1) introduce more nuance into PaymentProcessorExceptions - extend the exception class with PaymentProcessorConfigException, PaymentProcessingException or similar to differentiate 2) remove all the handling for invokeApi to have returned an error object. 3) fix the code that calls updateSubscriptionBillingInfo 4) ensure docs reflect that doPayment should throw an exception. AFAIK we have not yet documented other 'do' functions & I'd prefer to stdise them first
94ce42c
to
5a57460
Compare
Added MOP per @artfulrobot review |
Overview
Standardises error handling within paypal internal function
Before
Currently invokeAPI will return an error for a curl function and throw a processorException for an outcome other than success.
After
invokeAPI always throws an exception if it fails.
Technical Details
Failed transactions result in exceptions being thrown in invokeAPI. However, in the rarer scenario where the error is a curl error CRM_Core_Error objects are returned & (almost always) converted into exceptions & thrown
In just about every instance where it is called the Core_Error is converted into an exception anyway - this
can all be cleaned up as a follow up. The exceptions are
doQuery - called by doPayment
doDirectPayment - this is called by doPayment which converts it into an exception. Calling doDirectPayment directly was deprecated in 4.6
createRecurringPayments - called by doExpressCheckout which in already throws exceptions in other scenarios,
updateSubscriptionBillingInfo - we can update the one place that calls this in core as a follow up like #15676
However, note that an exception was already thrown in all these places in the more common error scenario of the action not succeeding as opposed
to the rare curl error scenario
Follow ons to consider
Comments
Anything else you would like the reviewer to note