Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

More descriptive error messages #26

Open
paparaka opened this issue Dec 3, 2022 · 0 comments
Open

More descriptive error messages #26

paparaka opened this issue Dec 3, 2022 · 0 comments

Comments

@paparaka
Copy link

paparaka commented Dec 3, 2022

Description:

When providing an incorect request body, the error messge is not descriptive enough.

Example:

from typeform import Typeform

r = Typeform("XXXXXXXX").forms.create(data={
    "title": "Incorrect form payload",
    "type": "quiz",
    "theme": https://api.typeform.com/themes/GKFi5U"
})

Raises the following exception:

...
File ~/Projects/coef/typeform-python-sdk/typeform/client.py:41, in Client.__validator(self, result)
     39 if type(body) is dict and body.get('code', None) is not None:
     40     print(body)
---> 41     raise Exception(body.get('description'))
     42 elif result.status_code >= 400:
     43     raise Exception(result.reason)

Exception: The payload is invalid.

If you are to intercept the HTTP response, you will receive a much more verbose error message:

{
    "code": "VALIDATION_ERROR",
    "description": "The payload is invalid.",
    "details": [
        {
            "code": "WRONG_TYPE",
            "description": "should be object,null",
            "field": "/theme",
            "in": "body"
        }
    ]
}

Motivation for or Use Case:

I'd like to handle errors better and understand where the issue is

Related Issues - has a similar issue been reported before?:

#16 Invalid payload error when creating a new Typeform

Environment Configuration:

Latest revision at: ccfe1ec

Suggest a Fix:

# in typeform/client.py L39:
if type(body) is dict and body.get('code', None) is not None:
            print(f"Error code: {body.get('code')}")
            print(f"Error details: {body.get('details')}")
            raise Exception(body.get('description'))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant