Skip to content

Return more useful errors #4

@cbetta

Description

@cbetta
Contributor

In the ruby library I've tried to catch most errors and bubble them up in a meaningful way. For example when I send a fax to a number that I'm not yet allowed to send a fax to I get:

fax = interfax.deliver(faxNumber: "+11111111112", file: 'spec/test.pdf')

InterFAX::Client::BadRequestError: Bad request (400): {"code":-111,"message":"Attempting to fax to a number that is not the designated fax number in a developer account","moreInfo":null}

In this library I get

>>> fax = interfax.deliver(fax_number="+442084978650", files=["tests/test.pdf"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "interfax/outbound.py", line 20, in deliver
    files=self._generate_files(files))
  File "interfax/client.py", line 76, in post
    return self._request('POST', url, **kwargs)
  File "interfax/client.py", line 89, in _request
    return self._parse_response(request(method, url, **kwargs))
  File "interfax/client.py", line 117, in _parse_response
    response.raise_for_status()
  File "/Users/cbetta/.pyenv/versions/2.7.12/lib/python2.7/site-packages/requests/models.py", line 862, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://rest.interfax.net/outbound/faxes?faxNumber=%2B442084978650

Activity

cbetta

cbetta commented on Oct 7, 2016

@cbetta
ContributorAuthor
danielknell

danielknell commented on Oct 10, 2016

@danielknell
Contributor

I did that initially but that error class has additional info that could be useful when debugging, and seemed more sensible than copying all that data across into a new hierarchy of errors, open to changing it though.

cbetta

cbetta commented on Oct 10, 2016

@cbetta
ContributorAuthor

@danielknell oh I agree on that. I'm not too worried about wrapping it in new error objects, that's just a convenience. What I am more worried about is that my error exposes the JSON body:

{"code":-111,"message":"Attempting to fax to a number that is not the designated fax number in a developer account","moreInfo":null}

Which is actually useful to the end user. Your code just tells me Bad Request without context.

cbetta

cbetta commented on Feb 1, 2017

@cbetta
ContributorAuthor

@danielknell where did we leave this?

danielknell

danielknell commented on Feb 2, 2017

@danielknell
Contributor

I got weighed down with other stuff and then forgot about it, sorry, i will try and find some time to look soon.

cbetta

cbetta commented on Feb 2, 2017

@cbetta
ContributorAuthor

Thanks @danielknell, any time you might have available to make this change would be much appreciated.

removed their assignment
on Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cbetta@danielknell

        Issue actions

          Return more useful errors · Issue #4 · interfax/interfax-python