in reply to EyeBall stumps BodBall (Error Handling)
I similarly urge you to get into the habit of thinking long and hard about your module's error handling well before you release it, and for the same reasons.
You'll be pleased to hear that I thought at length about error handling before I wrote Business::Stripe::WebCheckout. A consistent approach has been carried over into my other Stripe modules:
Business::Stripe::Subscription
Business::Stripe::Webhook
AFAICT, your basic error handling strategy is for your methods to set the error property
Almost...
The modules set error in any error. The modules provide the success method which returns true on success or false if there was an error. The user of the module is expected to check success. The error method returns the error property so that the user can understand why success is false.
These modules are designed to be used on a webserver. As such, calling die is not helpful to anyone. The end user, the person browsing the website, will probably get an HTTP 500 error and the user of the module is unlikely to detect that quickly.
That's what I meant by: "However, I will not call die. I find it frustrating when modules die"
Instead, I opted for the default error handing approach of DBI. I use this module in default mode (i.e. with RaiseError false) and only turn on RaiseError for debugging, not for live code.
I'm not sure my Stripe modules warrant the equivalent of RaiseError in them. I may be wrong here.
Specifically with Business::Stripe::Webhook, this is designed for building scripts to listen for calls from Stripe to a webhook endpoint. Stripe specifies that the endpoint MUST give a JSON encoded response. The module provides a method for doing this. If the payload from Stripe is invalid or has been changed by the user of the module, then Stripe still needs this reply. If we were to call die then Stripe will not get the reply and may invalidate the endpoint. So not calling die is a very deliberate design decision.
I think a clear statement of your overall error-handling strategy, combined with a couple of real-world examples of handling common errors you've experienced when using your module, would be invaluable to your users
Thank you for this, I shall include it in the next release of each of the Stripe modules.
I work on my own and build modules that are for my use. They only get released if I think they will also be is use for other people. But, like everyone, I suffer from what I call "the curse of knowledge". It is obvious to me what it is supposed to do and how to use it. So it is very difficult to know which bit to explain in full detail and which only need a little explanation.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: EyeBall stumps BodBall
by eyepopslikeamosquito (Archbishop) on Jul 17, 2023 at 09:07 UTC | |
by Bod (Parson) on Jul 23, 2023 at 21:07 UTC | |
by eyepopslikeamosquito (Archbishop) on Jul 24, 2023 at 08:58 UTC | |
by Bod (Parson) on Aug 01, 2023 at 22:24 UTC | |
by eyepopslikeamosquito (Archbishop) on Aug 02, 2023 at 02:49 UTC | |
| |
Re^2: EyeBall stumps BodBall
by kcott (Archbishop) on Jul 09, 2023 at 11:50 UTC | |
by Bod (Parson) on Jul 23, 2023 at 21:13 UTC | |
Re^2: EyeBall stumps BodBall
by etj (Priest) on May 19, 2024 at 13:23 UTC |