From d25ee22e34a7682f3f0823b749597bd1dc28441a Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 28 Jul 2020 11:07:02 -0700 Subject: [PATCH] reduce section on http status codes formatting in sentry section --- docs/errorhandling.rst | 67 ++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/docs/errorhandling.rst b/docs/errorhandling.rst index 48097d9b..5d1dbf3b 100644 --- a/docs/errorhandling.rst +++ b/docs/errorhandling.rst @@ -24,42 +24,8 @@ page for you and log the exception to the :attr:`~flask.Flask.logger`. But there is more you can do, and we will cover some better setups to deal with errors including custom exceptions and 3rd party tools. -Common Error Codes ------------------- -The following error codes are some that are often displayed to the user, -even if the application behaves correctly: - -*400 Bad Request* - When the server will not process the request due to something that - the server perceives to be a client error. Such as malformed request - syntax, missing query parameters, etc. - -*403 Forbidden* - If you have some kind of access control on your website, you will have - to send a 403 code for disallowed resources. So make sure the user - is not lost when they try to access a forbidden resource. - -*404 Not Found* - The good old "chap, you made a mistake typing that URL" message. So - common that even novices to the internet know that 404 means: damn, - the thing I was looking for is not there. It's a very good idea to - make sure there is actually something useful on a 404 page, at least a - link back to the index. - -*410 Gone* - Did you know that there the "404 Not Found" has a brother named "410 - Gone"? Few people actually implement that, but the idea is that - resources that previously existed and got deleted answer with 410 - instead of 404. If you are not deleting documents permanently from - the database but just mark them as deleted, do the user a favour and - use the 410 code instead and display a message that what they were - looking for was deleted for all eternity. - -*500 Internal Server Error* - Usually happens on programming errors or if the server is overloaded. - A terribly good idea is to have a nice page there, because your - application *will* fail sooner or later. +.. _error-logging-tools: Error Logging Tools ------------------- @@ -75,31 +41,36 @@ aggregates duplicate errors, captures the full stack trace and local variables for debugging, and sends you mails based on new errors or frequency thresholds. -To use Sentry you need to install the `sentry-sdk` client with extra `flask` dependencies:: +To use Sentry you need to install the ``sentry-sdk`` client with extra +``flask`` dependencies. + +.. code-block:: text $ pip install sentry-sdk[flask] -And then add this to your Flask app:: +And then add this to your Flask app: + +.. code-block:: python import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration sentry_sdk.init('YOUR_DSN_HERE',integrations=[FlaskIntegration()]) -The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get -from your Sentry installation. +The ``YOUR_DSN_HERE`` value needs to be replaced with the DSN value you +get from your Sentry installation. After installation, failures leading to an Internal Server Error are automatically reported to Sentry and from there you can receive error notifications. -Follow-up reads: +See also: -* Sentry also supports catching errors from your worker queue (RQ, Celery) in a - similar fashion. See the `Python SDK docs - `_ for more information. -* `Getting started with Sentry `_ -* `Flask-specific documentation `_. +- Sentry also supports catching errors from a worker queue + (RQ, Celery, etc.) in a similar fashion. See the `Python SDK docs + `__ for more information. +- `Getting started with Sentry `__ +- `Flask-specific documentation `__ .. _error-handlers: @@ -107,6 +78,12 @@ Follow-up reads: Error Handlers -------------- +When an error occurs in Flask, an appropriate `HTTP status code +`__ will be +returned. 400-499 indicate errors with the client's request data, or +about the data requested. 500-599 indicate errors with the server or +application itself. + You might want to show custom error pages to the user when an error occurs. This can be done by registering error handlers.