{"id":14979080,"url":"https://github.com/developerrsquared/http-exceptions","last_synced_at":"2025-10-28T14:30:47.787Z","repository":{"id":37956855,"uuid":"412934757","full_name":"DeveloperRSquared/http-exceptions","owner":"DeveloperRSquared","description":"Raisable HTTP Exceptions","archived":false,"fork":false,"pushed_at":"2025-02-10T17:12:56.000Z","size":263,"stargazers_count":3,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T18:25:04.745Z","etag":null,"topics":["api","exceptions","http","python","python3","rest","web"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/http-exceptions/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeveloperRSquared.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["rikhilrai"],"custom":"https://www.paypal.me/rikhilrai"}},"created_at":"2021-10-02T23:41:40.000Z","updated_at":"2024-05-28T08:13:44.000Z","dependencies_parsed_at":"2023-12-11T18:27:08.165Z","dependency_job_id":"ada9ccad-9d02-43fe-9bf1-c758c12c0835","html_url":"https://github.com/DeveloperRSquared/http-exceptions","commit_stats":{"total_commits":101,"total_committers":3,"mean_commits":"33.666666666666664","dds":0.594059405940594,"last_synced_commit":"66cc48c151cca09471dc7fa61a60056470c81825"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperRSquared%2Fhttp-exceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperRSquared%2Fhttp-exceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperRSquared%2Fhttp-exceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperRSquared%2Fhttp-exceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeveloperRSquared","download_url":"https://codeload.github.com/DeveloperRSquared/http-exceptions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238662691,"owners_count":19509650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","exceptions","http","python","python3","rest","web"],"created_at":"2024-09-24T13:59:11.814Z","updated_at":"2025-10-28T14:30:47.203Z","avatar_url":"https://github.com/DeveloperRSquared.png","language":"Python","readme":"# HTTP Exceptions\n\n[![Publish](https://github.com/DeveloperRSquared/http-exceptions/actions/workflows/publish.yml/badge.svg)](https://github.com/DeveloperRSquared/http-exceptions/actions/workflows/publish.yml)\n\n[![Python 3.7+](https://img.shields.io/badge/python-3.7+-brightgreen.svg)](#http-exceptions)\n[![PyPI - License](https://img.shields.io/pypi/l/http-exceptions.svg)](LICENSE)\n[![PyPI - Version](https://img.shields.io/pypi/v/http-exceptions.svg)](https://pypi.org/project/http-exceptions)\n\n[![CodeQL](https://github.com/DeveloperRSquared/http-exceptions/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/DeveloperRSquared/http-exceptions/actions/workflows/codeql-analysis.yml)\n[![codecov](https://codecov.io/gh/DeveloperRSquared/http-exceptions/branch/main/graph/badge.svg?token=8SJ30A2GV7)](https://codecov.io/gh/DeveloperRSquared/http-exceptions)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/DeveloperRSquared/http-exceptions/main.svg)](https://results.pre-commit.ci/latest/github/DeveloperRSquared/http-exceptions/main)\n\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat\u0026labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n\nRaisable HTTP Exceptions\n\n## Install\n\nSimply install the package from [PyPI](https://pypi.org/project/http-exceptions/).\n\n```sh\n$ pip install -U http-exceptions\n```\n\nAnd that is it, you are ready to raise HTTP Exceptions.\n\n## What is it good for?\n\n1. Saves writing boilerplate code:\n\n   Converts this:\n\n   ```py\n   # e.g. app/internal.py\n   def some_function() -\u003e None:\n       raise SomeError()\n\n   # e.g. app/api.py\n   def api(request: Request) -\u003e Response:\n       try:\n           response = some_function()\n       except SomeError:\n           response = Response(status_code=403)\n       return response\n   ```\n\n   into this:\n\n   ```py\n   # e.g. app/internal.py\n   from http_exceptions import ForbiddenException\n\n   def some_function() -\u003e None:\n       raise ForbiddenException()\n\n   # e.g. app/api.py\n   def api(request: Request) -\u003e None:\n       return some_function()\n   ```\n\n2. Dynamic exception raising:\n\n   ```py\n   from http_exceptions import HTTPException\n\n   def raise_from_status(response: Response) -\u003e None:\n       if 400 \u003c= response.status \u003c 600:\n           raise HTTPException.from_status_code(status_code=response.status_code)(message=response.text)\n   ```\n\n   ```py\n   \u003e\u003e\u003e response = Response(status_code=403)\n   \u003e\u003e\u003e raise_from_status(response=response)  # ForbiddenException raised\n   ```\n\n## What else?\n\n### `HTTPException`\n\nBase class that provides all the exceptions to be raised.\n\n### `HTTPExceptions.from_status_code(status_code=status_code)`\n\nReturns the relevant Exception corresponding to `status_code`\n\ne.g. `HTTPExceptions.from_status_code(status_code=431)` -\u003e `RequestHeaderFieldsTooLargeException`\n\n### `ClientException`\n\nSubclass of `HTTPException` serving as a base class for exceptions with statuses in the [400, 499] range.\n\n```py\nfrom http_exceptions import ClientException, RequestHeaderFieldsTooLargeException\n\ntry:\n    raise RequestHeaderFieldsTooLargeException  # 431 - Client exception\nexcept ClientException:\n    # exception is caught here\n    pass\n```\n\n### `ServerException`\n\nSubclass of `HTTPException` serving as a base class for exceptions with statuses in the [500, 599] range.\n\n```py\nfrom http_exceptions import HTTPVersionNotSupportedException, ServerException\n\ntry:\n    raise HTTPVersionNotSupportedException  # 505 - Server exception\nexcept ServerException:\n    # exception is caught here\n    pass\n```\n\n## Available Exceptions\n\n### Client Exceptions: `400 \u003c= status \u003c= 499`\n\n```py\n400: BadRequestException\n401: UnauthorizedException\n402: PaymentRequiredException\n403: ForbiddenException\n404: NotFoundException\n405: MethodNotAllowedException\n406: NotAcceptableException\n407: ProxyAuthenticationRequiredException\n408: RequestTimeoutException\n409: ConflictException\n410: GoneException\n411: LengthRequiredException\n412: PreconditionFailedException\n413: PayloadTooLargeException\n414: URITooLongException\n415: UnsupportedMediaTypeException\n416: RangeNotSatisfiableException\n417: ExpectationFailedException\n418: ImATeapotException\n421: MisdirectedRequestException\n422: UnprocessableEntityException\n423: LockedException\n424: FailedDependencyException\n425: TooEarlyException\n426: UpgradeRequiredException\n428: PreconditionRequiredException\n429: TooManyRequestsException\n431: RequestHeaderFieldsTooLargeException\n444: NoResponseException\n451: UnavailableForLegalReasonsException\n```\n\n### Server Exceptions: `500 \u003c= status \u003c= 599`\n\n```py\n500: InternalServerErrorException\n501: NotImplementedException\n502: BadGatewayException\n503: ServiceUnavailableException\n504: GatewayTimeoutException\n505: HTTPVersionNotSupportedException\n506: VariantAlsoNegotiatesException\n507: InsufficientStorageException\n508: LoopDetectedException\n510: NotExtendedException\n511: NetworkAuthenticationRequiredException\n```\n\n## Contributing\n\nContributions are welcome via pull requests.\n\n### First time setup\n\n```sh\n$ git clone git@github.com:DeveloperRSquared/http-exceptions.git\n$ cd http-exceptions\n$ poetry install\n$ poetry shell\n```\n\nTools including black, mypy etc. will run automatically if you install [pre-commit](https://pre-commit.com) using the instructions below\n\n```sh\n$ pre-commit install\n$ pre-commit run --all-files\n```\n\n### Running tests\n\n```sh\n$ poetry run pytest\n```\n\n## Links\n\n- Source Code: \u003chttps://github.com/DeveloperRSquared/http-exceptions/\u003e\n- PyPI Releases: \u003chttps://pypi.org/project/http-exceptions/\u003e\n- Issue Tracker: \u003chttps://github.com/DeveloperRSquared/http-exceptions/issues/\u003e\n","funding_links":["https://github.com/sponsors/rikhilrai","https://www.paypal.me/rikhilrai"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperrsquared%2Fhttp-exceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeveloperrsquared%2Fhttp-exceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperrsquared%2Fhttp-exceptions/lists"}