{ "info": { "author": "isik-kaplan", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "[![Build Status](https://travis-ci.org/isik-kaplan/django_http_exceptions.svg?branch=master)](https://travis-ci.org/isik-kaplan/django_http_exceptions)\n[![codecov](https://codecov.io/gh/isik-kaplan/django_http_exceptions/branch/master/graph/badge.svg)](https://codecov.io/gh/isik-kaplan/django_http_exceptions) \n[![Python 3.5+](https://img.shields.io/badge/python-3.5+-brightgreen.svg)](#)\n[![Django 2.0+](https://img.shields.io/badge/django-2.0+-brightgreen.svg)](#)\n[![PyPI - License](https://img.shields.io/pypi/l/django_http_exceptions.svg)](https://pypi.org/project/django-http-exceptions/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/django_http_exceptions.svg)](https://pypi.org/project/django-http-exceptions/)\n\n\n## What is *django_http_exceptions*?\n\nIt is raisable exceptions for your django views.\n\n\n\n## What is it good for?\n\nIt makes this \n\n````py\ndef some_function():\n raise SomeError\n\ndef view(request):\n try:\n response = some_function()\n except SomeError:\n response = HttpResponse(status=403)\n return response\n````\ninto this\n````py\nfrom django_http_exceptions import HTTPExceptions\ndef some_function():\n raise HTTPExcetions.FORBIDDEN # HTTPExceptions.from_status(403)\n\ndef view(request):\n return some_function() \n \n````\n\nmeaning that is saves you from boilerplate code. \n\nIt also allows you to hook default views to **all possible http response codes**, meaning that you can use more than the 5-6 django provided error handlers.\n\n\n\n## How to use it?\n\nJust two middlewares, lower the better, and you are done.\n\n````python\nMIDDLEWARE = [\n ...,\n 'django_http_exceptions.middleware.ExceptionHandlerMiddleware',\n 'django_http_exceptions.middleware.ThreadLocalRequestMiddleware',\n ...\n]\n````\n\nAnd that is it, you are ready to raise your http exceptions.\n\n\n\n## What else? \n\n\n#### `HTTPExceptions`\nBase class that provides all the exceptions to be raised.\n\n\n#### `HTTPExceptions.from_status(status)` \nIn case you don't want to write \n`HTTPExceptions.REQUEST_HEADER_FIELDS_TOO_LARGE` \nYou can just write \n`HTTPExceptions.from_status(431)`\n\n\n#### `HTTPExceptions.BASE_EXCEPTON` \nThe base exception for all http exception\n\n#### `HTTPExceptions.register_base_exception(exception)`\nGiven that `exception` is a class that inherits from `HTTPException` you can customize the exceptions.\nKeep in mind that `HTTPException` is an `Exception` subclass itself.\n\n\n#### `HTTPExceptions.BASE_EXCEPTION.with_response(response)` \nThis is the method for raising exceptions with a response. You can put any response in this method while raising your\nerror.\n \nLet's say you have a view named `index`, then this example would return what `index` function would return, but with\nstatus code `410` \n`HTTPExceptions.GONE.with_response(index(request))`\n\n\n#### `HTTPExceptions.BASE_EXCEPTION.with_content(content)` \nThis method allow to raise an **HTTPException** with a custom message (can be either `str` or `bytes`).\n\nFor instance, `HTTPExceptions.NOT_FOUND.with_content(\"The user named 'username' could not be found\")`\nwould return something equivalent to `HttpResponse(\"The user named 'username' could not be found\", status=404)`.\n\n\n#### `HTTPExceptions.BASE_EXCEPTION.register_default_view(view)` \n`view` is a function that takes only one argument, `request` when you register a default view to an error class with\n`HTTPExceptions.NOT_FOUND.register_defaul_view(view)` when `HTTPExceptions.GONE` is raised it returns the view function, \nbut again, with `404` status code. If the error has been raised with `.with_response`, that is used instead. \n\n\n#### `get_current_request`\n\nThis function gets you the current request anywhere in your django application, making it easier for your dynamic error \nresponses to be created, like in the `HTTPExceptions.GONE.with_response(index(request))` example.\n \n \n#### `ExceptionHandlerMiddleware` \n\nJust there for to exception handling to work.\n \n \n#### `ThreadLocalRequestMiddleware` \n \nJust there for to `get_current_request` to work.\n\n\n#### `errorify(error)`\n\nDecorator that turns a view (both class and function) into an http error\n\n````python\n@errorify(HTTPExceptions.PAYMENT_REQUIRED)\nclass Subscribe(TemplateView):\n template = SUBSCRIBE_TEMPLATE\n````\n\n \n## Avaliable Exceptions\n```py\nHTTPExceptions.CONTINUE # HTTPExceptions.from_status(100)\nHTTPExceptions.SWITCHING_PROTOCOLS # HTTPExceptions.from_status(101)\nHTTPExceptions.PROCESSING # HTTPExceptions.from_status(102)\nHTTPExceptions.OK # HTTPExceptions.from_status(200)\nHTTPExceptions.CREATED # HTTPExceptions.from_status(201)\nHTTPExceptions.ACCEPTED # HTTPExceptions.from_status(202)\nHTTPExceptions.NON_AUTHORITATIVE_INFORMATION # HTTPExceptions.from_status(203)\nHTTPExceptions.NO_CONTENT # HTTPExceptions.from_status(204)\nHTTPExceptions.RESET_CONTENT # HTTPExceptions.from_status(205)\nHTTPExceptions.PARTIAL_CONTENT # HTTPExceptions.from_status(206)\nHTTPExceptions.MULTI_STATUS # HTTPExceptions.from_status(207)\nHTTPExceptions.ALREADY_REPORTED # HTTPExceptions.from_status(208)\nHTTPExceptions.IM_USED # HTTPExceptions.from_status(226)\nHTTPExceptions.MULTIPLE_CHOICES # HTTPExceptions.from_status(300)\nHTTPExceptions.MOVED_PERMANENTLY # HTTPExceptions.from_status(301)\nHTTPExceptions.FOUND # HTTPExceptions.from_status(302)\nHTTPExceptions.SEE_OTHER # HTTPExceptions.from_status(303)\nHTTPExceptions.NOT_MODIFIED # HTTPExceptions.from_status(304)\nHTTPExceptions.USE_PROXY # HTTPExceptions.from_status(305)\nHTTPExceptions.TEMPORARY_REDIRECT # HTTPExceptions.from_status(307)\nHTTPExceptions.PERMANENT_REDIRECT # HTTPExceptions.from_status(308)\nHTTPExceptions.BAD_REQUEST # HTTPExceptions.from_status(400)\nHTTPExceptions.UNAUTHORIZED # HTTPExceptions.from_status(401)\nHTTPExceptions.PAYMENT_REQUIRED # HTTPExceptions.from_status(402)\nHTTPExceptions.FORBIDDEN # HTTPExceptions.from_status(403)\nHTTPExceptions.NOT_FOUND # HTTPExceptions.from_status(404)\nHTTPExceptions.METHOD_NOT_ALLOWED # HTTPExceptions.from_status(405)\nHTTPExceptions.NOT_ACCEPTABLE # HTTPExceptions.from_status(406)\nHTTPExceptions.PROXY_AUTHENTICATION_REQUIRED # HTTPExceptions.from_status(407)\nHTTPExceptions.REQUEST_TIMEOUT # HTTPExceptions.from_status(408)\nHTTPExceptions.CONFLICT # HTTPExceptions.from_status(409)\nHTTPExceptions.GONE # HTTPExceptions.from_status(410)\nHTTPExceptions.LENGTH_REQUIRED # HTTPExceptions.from_status(411)\nHTTPExceptions.PRECONDITION_FAILED # HTTPExceptions.from_status(412)\nHTTPExceptions.REQUEST_ENTITY_TOO_LARGE # HTTPExceptions.from_status(413)\nHTTPExceptions.REQUEST_URI_TOO_LONG # HTTPExceptions.from_status(414)\nHTTPExceptions.UNSUPPORTED_MEDIA_TYPE # HTTPExceptions.from_status(415)\nHTTPExceptions.REQUESTED_RANGE_NOT_SATISFIABLE # HTTPExceptions.from_status(416)\nHTTPExceptions.EXPECTATION_FAILED # HTTPExceptions.from_status(417)\nHTTPExceptions.UNPROCESSABLE_ENTITY # HTTPExceptions.from_status(422)\nHTTPExceptions.LOCKED # HTTPExceptions.from_status(423)\nHTTPExceptions.FAILED_DEPENDENCY # HTTPExceptions.from_status(424)\nHTTPExceptions.UPGRADE_REQUIRED # HTTPExceptions.from_status(426)\nHTTPExceptions.PRECONDITION_REQUIRED # HTTPExceptions.from_status(428)\nHTTPExceptions.TOO_MANY_REQUESTS # HTTPExceptions.from_status(429)\nHTTPExceptions.REQUEST_HEADER_FIELDS_TOO_LARGE # HTTPExceptions.from_status(431)\nHTTPExceptions.INTERNAL_SERVER_ERROR # HTTPExceptions.from_status(500)\nHTTPExceptions.NOT_IMPLEMENTED # HTTPExceptions.from_status(501)\nHTTPExceptions.BAD_GATEWAY # HTTPExceptions.from_status(502)\nHTTPExceptions.SERVICE_UNAVAILABLE # HTTPExceptions.from_status(503)\nHTTPExceptions.GATEWAY_TIMEOUT # HTTPExceptions.from_status(504)\nHTTPExceptions.HTTP_VERSION_NOT_SUPPORTED # HTTPExceptions.from_status(505)\nHTTPExceptions.VARIANT_ALSO_NEGOTIATES # HTTPExceptions.from_status(506)\nHTTPExceptions.INSUFFICIENT_STORAGE # HTTPExceptions.from_status(507)\nHTTPExceptions.LOOP_DETECTED # HTTPExceptions.from_status(508)\nHTTPExceptions.NOT_EXTENDED # HTTPExceptions.from_status(510)\nHTTPExceptions.NETWORK_AUTHENTICATION_REQUIRED # HTTPExceptions.from_status(511)\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/isik-kaplan/django_http_exceptions", "keywords": "", "license": "APGL-3.0", "maintainer": "", "maintainer_email": "", "name": "django-http-exceptions", "package_url": "https://pypi.org/project/django-http-exceptions/", "platform": "", "project_url": "https://pypi.org/project/django-http-exceptions/", "project_urls": { "Homepage": "https://github.com/isik-kaplan/django_http_exceptions" }, "release_url": "https://pypi.org/project/django-http-exceptions/1.2.0/", "requires_dist": null, "requires_python": ">=3.5", "summary": "django raisable http exceptions", "version": "1.2.0" }, "last_serial": 5778802, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "11649bb765daca79e523ed73878bb2b7", "sha256": "e6a0d7564069fe52c6ec7aa25f63478ad2171e1b5051baca724a8e0600a5ece9" }, "downloads": -1, "filename": "django_http_exceptions-1.0.0.tar.gz", "has_sig": false, "md5_digest": "11649bb765daca79e523ed73878bb2b7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4350, "upload_time": "2019-05-03T12:46:15", "url": "https://files.pythonhosted.org/packages/30/9e/3cc8197d532dfc9881925b4538b6dad4560540ee2da98caa7a2ffe33c41d/django_http_exceptions-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "f0a078a64ab421b3c2e4d3d502068f68", "sha256": "25053e80c8288470082c02390798ee868bea8d91d7e80529e4a1709bf6b6760e" }, "downloads": -1, "filename": "django_http_exceptions-1.0.1.tar.gz", "has_sig": false, "md5_digest": "f0a078a64ab421b3c2e4d3d502068f68", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4995, "upload_time": "2019-05-03T13:15:43", "url": "https://files.pythonhosted.org/packages/05/b4/2a7f1d9aa86588af573e4b1d8979c9229de6d4e4fa312d4fbbaae7484a87/django_http_exceptions-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "6f36d19dfaf9c74b5bbf91a2f4e73684", "sha256": "becbc992dbd84ec05f3ed35dd92bba037d81c5c3eadc6a235d2e3794472c7966" }, "downloads": -1, "filename": "django_http_exceptions-1.0.2.tar.gz", "has_sig": false, "md5_digest": "6f36d19dfaf9c74b5bbf91a2f4e73684", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5433, "upload_time": "2019-05-30T21:32:41", "url": "https://files.pythonhosted.org/packages/5d/82/74e11e8647adfd4f73c17d56ab45d5c83774d105bc1d7b638b4cfb73ca16/django_http_exceptions-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "ea0bcc8c0c19ea118e2c2dabb35f821a", "sha256": "8dea6cba48e1306c444fbf2647cb920717499af747d6d1ac80c08844566c0d46" }, "downloads": -1, "filename": "django_http_exceptions-1.0.3.tar.gz", "has_sig": false, "md5_digest": "ea0bcc8c0c19ea118e2c2dabb35f821a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5429, "upload_time": "2019-07-11T13:19:26", "url": "https://files.pythonhosted.org/packages/ec/1d/74c5a7ce156fa0c5e78480ed9ae14ebac18fd9c93cd9496b04691b484cd3/django_http_exceptions-1.0.3.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "cc6727d6907214c82fe509bca3fe71ae", "sha256": "4d468ac28a6b92db83d5467e520bc4ae4ae9bee773e185f6774fadc25760d9d2" }, "downloads": -1, "filename": "django_http_exceptions-1.1.0.tar.gz", "has_sig": false, "md5_digest": "cc6727d6907214c82fe509bca3fe71ae", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5874, "upload_time": "2019-07-24T04:20:33", "url": "https://files.pythonhosted.org/packages/28/fd/5a6729516e0c5c9c180a166d88cb0569b940e497aa52e2ece21437054fb2/django_http_exceptions-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "5ee1e1db20318848bf6c9a4d15274c8e", "sha256": "65b9eda96eaf8e127aa3cf4502cf02a7f09f63f42e3b90397cfec1c61cc75f81" }, "downloads": -1, "filename": "django_http_exceptions-1.2.0.tar.gz", "has_sig": false, "md5_digest": "5ee1e1db20318848bf6c9a4d15274c8e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 6256, "upload_time": "2019-09-04T01:24:06", "url": "https://files.pythonhosted.org/packages/1d/53/2d1c9ed482b4c5fa35cd5adcd165b21936cc1eb5157a1ff341979dfba1e4/django_http_exceptions-1.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5ee1e1db20318848bf6c9a4d15274c8e", "sha256": "65b9eda96eaf8e127aa3cf4502cf02a7f09f63f42e3b90397cfec1c61cc75f81" }, "downloads": -1, "filename": "django_http_exceptions-1.2.0.tar.gz", "has_sig": false, "md5_digest": "5ee1e1db20318848bf6c9a4d15274c8e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 6256, "upload_time": "2019-09-04T01:24:06", "url": "https://files.pythonhosted.org/packages/1d/53/2d1c9ed482b4c5fa35cd5adcd165b21936cc1eb5157a1ff341979dfba1e4/django_http_exceptions-1.2.0.tar.gz" } ] }