gocardless-pro-python icon indicating copy to clipboard operation
gocardless-pro-python copied to clipboard

Add specific type Errors

Open AndreasBackx opened this issue 9 years ago • 4 comments

The API documentation has a ton of errors listed, would it be possible to have these exact errors/exceptions be raised by the library? Currently we have to check for the errors inside of the Error's error (that sentence is a bit ridiculous, but it makes it clear).

We end up with the following constantly:

try:
    instance.from_api(
        instance.api.create,
        params=given
    )
except GoCardlessProError as e:
    raise DjangoGoCardlessException.from_gocardless_exception(e)
instance.save(*args, **kwargs)

The DjangoGoCardlessException.from_gocardless_exception(e) would raise the exception that should've been raised by the library.

Instead of that something like this:

try:
    instance.from_api(
        instance.api.create,
        params=given
    )
except AccessTokenNotFound as e:
    # Perhaps not catch it here, but elsewhere.

AndreasBackx avatar Mar 29 '16 21:03 AndreasBackx

Hi Andreas,

Thanks for this. I'll leave it to @hmarr, who's on holiday right now but back in the next few days.

greysteil avatar Mar 30 '16 08:03 greysteil

I feel like the library doesn't offer a lot in terms of saving development time. I wish there was a more advanced library available for GoCardless that perhaps wasn't generated by Crank. Perhaps open source Crank because we also essentially don't know what Crank does besides generate this library?

A simple example of a quality of life change would be that the resources from the library could do some simple validation locally. Validation like required fields and min/max length fields. Most of these validations probably done by a project using this library.

AndreasBackx avatar Mar 30 '16 14:03 AndreasBackx

Thanks for reporting this @AndreasBackx. I can definitely see how more granular error types would help.

Currently, it's a non-trivial change as the library is generated from our API schema, which doesn't contain details of error types. However, adding errors to the schema is something we'll consider in due course.

We're keen to open source Crank, and plan to in the future, but unfortunately can't commit to a date right now.

hmarr avatar Apr 05 '16 18:04 hmarr

Any update on this? I don't see Crank open sourced yet nor does this issue seem to have evolved any further after over a year.

AndreasBackx avatar May 04 '17 18:05 AndreasBackx