Skip to content
Myr

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

1 file+22 added−45 removed

modified:docs/errorhandling.rst+22 added-45 removed
22 unmodified lines
2324But there is more you can do, and we will cover some better setups to deal25with errors including custom exceptions and 3rd party tools.2627Common Error Codes28------------------2730The following error codes are some that are often displayed to the user,31even if the application behaves correctly:28.. _error-logging-tools:2933*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.3738*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.4243*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.4950*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.5859*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.6330Error Logging Tools31-------------------3233Sending error mails, even if just for critical ones, can become
6 unmodified lines
40aggregates duplicate errors, captures the full stack trace and local41variables for debugging, and sends you mails based on new errors or42frequency thresholds.4378To use Sentry you need to install the `sentry-sdk` client with extra `flask` dependencies::44To use Sentry you need to install the ``sentry-sdk`` client with extra45``flask`` dependencies.4647.. code-block:: text4849 $ pip install sentry-sdk[flask]5082And then add this to your Flask app::51And then add this to your Flask app:5253.. code-block:: python5455 import sentry_sdk56 from sentry_sdk.integrations.flask import FlaskIntegration5758 sentry_sdk.init('YOUR_DSN_HERE',integrations=[FlaskIntegration()])5989The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get90from your Sentry installation.60The ``YOUR_DSN_HERE`` value needs to be replaced with the DSN value you61get from your Sentry installation.6263After installation, failures leading to an Internal Server Error64are automatically reported to Sentry and from there you can65receive error notifications.6696Follow-up reads:67See also:6898* 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/>`__747576.. _error-handlers:7778Error Handlers79--------------8081When an error occurs in Flask, an appropriate `HTTP status code82<https://developer.mozilla.org/en-US/docs/Web/HTTP/Status>`__ will be83returned. 400-499 indicate errors with the client's request data, or84about the data requested. 500-599 indicate errors with the server or85application itself.8687You might want to show custom error pages to the user when an error occurs.88This can be done by registering error handlers.8990An error handler is a function that returns a response when a type of error is
501 unmodified lines