Handling Errors
Learn how to handle errors gracefully without crashing your app
Overview
Errors are unavoidable especially if your query parameters are determined by user inputs. The status
field in each response allows you to check the
state of your request (whether successful or otherwise).
Example
Below is a sample code that shows you how to handle errors/exceptions from the API:
The validate_vat()
function accepts a vat_number argument which is a user input. This function uses the VatAPI.validate()
method to validate a VAT number.
It uses exception handling to manage the two error kinds that might occur in your app - TypeError and JSON error messages.
This setup works with any Python app(mobile, desktop, web). Also, it can be used with all the API classes and their methods. Simply replace the required methods and API class where necessary.