Smartsheet SDK exception handling

207 Views Asked by At

I am trying to write try except block for smartsheet aPI using python sdk, specially in cases where the API response to call returns error object rather than a usual index result object. Could someone explain what kind of exception would I be catching. I am not sure if I would have to create custom exceptions of my own or whether there are some way to capture exceptions. The API document talks about the error messages, not handling the. Would be great if someone could share some simple examples around the same.

1

There are 1 best solutions below

0
daveskull81 On

Knowing what a successful response will look like you could try checking for the error response. For example, running a get_row with an invalid rowId will result in this error:

{"requestResponse": null, "result": {"code": 1006, "name": "NotFoundError", "recommendation": "Do not retry without fixing the problem. Hint: Verify that specified URI is correct. If the URI contains an object ID, verify that the object ID is correct and that the requester has access to the corresponding object in Smartsheet.", "shouldRetry": false, "message": "Not Found", "statusCode": 404}}

Seeing requestResponse being null you can check the result object to know what the code is to look up in the Smartsheet API docs. Also, there is a recommendation parameter that gives next steps.