reduce section on http status codes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
formatting in sentry section
authored by David Lord · committed by David Lord · parent ba118b4 · Browse files · 1 file·+22 added−45 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+22 added−45 removed
- other:+22 added−45 removed
Provenance
- Commit
d25ee22- Tree
a74dc46- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
ba118b4
1 file changed+22 added−45 removed
modified:docs/errorhandling.rst+22 added-45 removed
22 unmodified lines23 24 But there is more you can do, and we will cover some better setups to deal25 with errors including custom exceptions and 3rd party tools.26 27-Common Error Codes28-------------------27 30-The following error codes are some that are often displayed to the user,31-even if the application behaves correctly:28+.. _error-logging-tools:29 33-*400 Bad Request*34- When the server will not process the request due to something that35- the server perceives to be a client error. Such as malformed request36- syntax, missing query parameters, etc.37-38-*403 Forbidden*39- If you have some kind of access control on your website, you will have40- to send a 403 code for disallowed resources. So make sure the user41- is not lost when they try to access a forbidden resource.42-43-*404 Not Found*44- The good old "chap, you made a mistake typing that URL" message. So45- common that even novices to the internet know that 404 means: damn,46- the thing I was looking for is not there. It's a very good idea to47- make sure there is actually something useful on a 404 page, at least a48- link back to the index.49-50-*410 Gone*51- Did you know that there the "404 Not Found" has a brother named "41052- Gone"? Few people actually implement that, but the idea is that53- resources that previously existed and got deleted answer with 41054- instead of 404. If you are not deleting documents permanently from55- the database but just mark them as deleted, do the user a favour and56- use the 410 code instead and display a message that what they were57- looking for was deleted for all eternity.58-59-*500 Internal Server Error*60- Usually happens on programming errors or if the server is overloaded.61- A terribly good idea is to have a nice page there, because your62- application *will* fail sooner or later.63-30 Error Logging Tools31 -------------------32 33 Sending error mails, even if just for critical ones, can become6 unmodified lines40 aggregates duplicate errors, captures the full stack trace and local41 variables for debugging, and sends you mails based on new errors or42 frequency thresholds.43 78-To use Sentry you need to install the `sentry-sdk` client with extra `flask` dependencies::44+To use Sentry you need to install the ``sentry-sdk`` client with extra45+``flask`` dependencies.46 47+.. code-block:: text48+49 $ pip install sentry-sdk[flask]50 82-And then add this to your Flask app::51+And then add this to your Flask app:52 53+.. code-block:: python54+55 import sentry_sdk56 from sentry_sdk.integrations.flask import FlaskIntegration57 58 sentry_sdk.init('YOUR_DSN_HERE',integrations=[FlaskIntegration()])59 89-The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get90-from your Sentry installation.60+The ``YOUR_DSN_HERE`` value needs to be replaced with the DSN value you61+get from your Sentry installation.62 63 After installation, failures leading to an Internal Server Error64 are automatically reported to Sentry and from there you can65 receive error notifications.66 96-Follow-up reads:67+See also:68 98-* Sentry also supports catching errors from your worker queue (RQ, Celery) in a99- similar fashion. See the `Python SDK docs100- <https://docs.sentry.io/platforms/python/>`_ for more information.101-* `Getting started with Sentry <https://docs.sentry.io/quickstart/?platform=python>`_102-* `Flask-specific documentation <https://docs.sentry.io/platforms/python/flask/>`_.69+- Sentry also supports catching errors from a worker queue70+ (RQ, Celery, etc.) in a similar fashion. See the `Python SDK docs71+ <https://docs.sentry.io/platforms/python/>`__ for more information.72+- `Getting started with Sentry <https://docs.sentry.io/quickstart/?platform=python>`__73+- `Flask-specific documentation <https://docs.sentry.io/platforms/python/flask/>`__74 75 76 .. _error-handlers:77 78 Error Handlers79 --------------80 81+When an error occurs in Flask, an appropriate `HTTP status code82+<https://developer.mozilla.org/en-US/docs/Web/HTTP/Status>`__ will be83+returned. 400-499 indicate errors with the client's request data, or84+about the data requested. 500-599 indicate errors with the server or85+application itself.86+87 You might want to show custom error pages to the user when an error occurs.88 This can be done by registering error handlers.89 90 An error handler is a function that returns a response when a type of error is501 unmodified lines