alitnk / monopay

💳 A node.js package for making payment transactions with different payment gateways
https://monopay.js.org
MIT License
114 stars 19 forks source link

New error handling method #42

Closed Keivan-sf closed 2 years ago

Keivan-sf commented 2 years ago

resolves #23

I've separated errors into 3 different exception objects such as discussed in #23 :

All errors extend an abstract class called MonopayError which offers some properties:

For the drivers that lack error codes, exceptions that are mostly thrown are GatewayFailureError's. Due to them being unrecognizable.

TODO

Keivan-sf commented 2 years ago

I've had the same thoughts about error codes being in a separate field as well. However it might lead to some confusion. For example if a developer sees both isIPGError and IPGErrorCode , they would assume the IPGErrorCode will be always available when isIPGError is true. Which is clearly not the correct approach in so many cases (e.g. internal errors , lack of error codes etc.) But on the other hand developers might want to make decisions based on them so it's really beneficial if we could somehow provide them. I thought maybe we could have an IPGResponse but we might get an empty response in some cases as well. Also it's an extra interface to deal with

I'm kinda unsure what we should do but I think providing a string|undefined field like errorCode is a good choice. If you're having the same thoughts I shall get on it

alitnk commented 2 years ago

That sounds good - Maybe we can add a jsdoc note and make these concerns clear

alitnk commented 2 years ago

lgtm!