Posts tagged

Error Handling

Rate Limiting, Error Handling, and Best Practices for API Design

Covers how to be a good API citizen when consuming external APIs and how to build well-designed APIs yourself. Explains how to read GitHub-style rate limit headers and automatically pause when the remaining quota hits zero. Demonstrates robust error handling using raise_for_status() and catching specific request exceptions. On the design side, covers six best practices: meaningful HTTP status codes, resource-centric RESTful endpoint naming, pagination, versioning, authentication, and comprehensive documentation with tools like Swagger.

Error Handling and Exceptions in Python

Explains Python's exception model and how try-except blocks prevent crashes by catching specific errors like ValueError and ZeroDivisionError. Covers grouping multiple exception types in one except clause, using finally to guarantee cleanup code runs regardless of outcome (demonstrated with file closing), and proactively raising exceptions with the raise keyword to enforce preconditions. Also shows how to define custom exception classes by subclassing Exception, and closes with a calculator exercise that handles invalid input and division by zero.