Skip to content

Can BadRequestError be made more intelligent / user friendly? #346

Closed
@thebjorn

Description

@thebjorn

Issue Summary

I was attempting to search for a contact by email and kept getting a BadRequestError with no further explanation of what might be wrong. Would it be possible to provide more debugging information with this error?

Steps to Reproduce

My initial code (the dkpassword module fetches passwords from our encrypted password database, but is the api is similar to os.environ - included for completeness only):

import os
import sendgrid
import dkpassword
#sg = sendgrid.SendGridAPIClient(apikey=os.environ['SENDGRID_API_TOKEN'])
sg = sendgrid.SendGridAPIClient(apikey=dkpassword.get('SENDGRID_API_TEST'))
r = sg.client.contactdb.recipients.search.get(query_paramas={'{email}': '[email protected]'})
print r.to_dict

the exception raised was:

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "w:\srv\venv\dev\lib\site-packages\python_http_client\client.py", line 227, in http_request
    return Response(self._make_request(opener, request))
  File "w:\srv\venv\dev\lib\site-packages\python_http_client\client.py", line 161, in _make_request
    raise exc
python_http_client.exceptions.BadRequestsError

based on the example code (https://github.com/sendgrid/sendgrid-python/blob/master/examples/contactdb/contactdb.py#L254) I wasn't sure if the field name should be in {} or not, so I tried without too, and got exactly the same error.

At this point I went on a detour via the conditions parameters and other wild goose chases.., until I noticed the extra a I had typed in query_paramas. I still got the BadRequestError, but when I removed the {..} around the field name I finally got data back (:yay:)

Would it be possible for BadRequestError to do a deeper parse of parameters expected vs. parameters provided to indicate what went wrong, or at least an exception message with more information (e.g. a check-list of what to check..)?

Technical details:

  • sendgrid-python Version: 5.2.0
  • Python Version: 2.7.13
  • OS: Windows 10

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

    Issue actions