diff options
author | 2018-02-28 23:33:35 +0000 | |
---|---|---|
committer | 2018-02-28 23:33:35 +0000 | |
commit | c2dfc1bb34e8153bc7372ce6056c6883616ece9b (patch) | |
tree | 0df39f5f8d60d3f528d48347e9a5c8b276875175 /pysite | |
parent | reduce memory allocation from 2GB to 512MB (#28) (diff) |
Add error messages (#30)
* Add error messages
Signed-off-by: JoeBanks13 <[email protected]>
* Remove un-used keyword arg from 404
* Assert for status code instead of full content
* PEP8
* test lint
* please coverage
* oh
* Exclude websockets.py from coverage
* Move code output into terminal
* Switch typewriter href protocol
* Add tests for websockets.py
* Abort previous commit, coveralls did not let coverage go down
* Add more pauses and request => response
* move css and js out, add typewriter JS to our own repo & add method for appending text in bulk.
* Enable REPL on 4XX and change error descriptions
* commas
* /error path
Diffstat (limited to 'pysite')
-rw-r--r-- | pysite/constants.py | 23 | ||||
-rw-r--r-- | pysite/database.py | 4 | ||||
-rw-r--r-- | pysite/decorators.py | 1 | ||||
-rw-r--r-- | pysite/mixins.py | 4 | ||||
-rw-r--r-- | pysite/route_manager.py | 1 | ||||
-rw-r--r-- | pysite/views/api/bot/user.py | 1 | ||||
-rw-r--r-- | pysite/views/error_handlers/http_404.py | 12 | ||||
-rw-r--r-- | pysite/views/error_handlers/http_4xx.py | 22 | ||||
-rw-r--r-- | pysite/views/error_handlers/http_5xx.py | 17 | ||||
-rw-r--r-- | pysite/views/main/abort.py | 12 | ||||
-rw-r--r-- | pysite/views/main/error.py | 12 | ||||
-rw-r--r-- | pysite/views/tests/index.py | 1 | ||||
-rw-r--r-- | pysite/websockets.py | 1 |
13 files changed, 86 insertions, 25 deletions
diff --git a/pysite/constants.py b/pysite/constants.py index 59febcc9..f70f48ad 100644 --- a/pysite/constants.py +++ b/pysite/constants.py @@ -20,3 +20,26 @@ OWNER_ROLE = 267627879762755584 ADMIN_ROLE = 267628507062992896 MODERATOR_ROLE = 267629731250176001 HELPER_ROLE = 267630620367257601 + +ERROR_DESCRIPTIONS = { + # 5XX + 500: "The server encountered an unexpected error ._.", + 501: "Woah! You seem to have found something we haven't even implemented yet!", + 502: "This is weird, one of our upstream servers seems to have experienced an error.", + 503: "Looks like one of our services is down for maintenance and couldn't respond to your request.", + 504: "Looks like an upstream server experienced a timeout while we tried to talk to it!", + 505: "You're using an old HTTP version. It might be time to upgrade your browser.", + # 4XX + 400: "You sent us a request that we don't know what to do with.", + 401: "Nope! You'll need to authenticate before we let you do that.", + 403: "No way! You're not allowed to do that.", + 404: "We looked, but we couldn't seem to find that page.", + 405: "That's a real page, but you can't use that method.", + 408: "We waited a really long time, but never got your request.", + 410: "This used to be here, but it's gone now.", + 411: "You forgot to tell us the length of the content.", + 413: "No way! That payload is, like, way too big!", + 415: "The thing you sent has the wrong format.", + 418: "Sorry, I'm not a server, I'm a teapot.", + 429: "Please don't send us that many requests." +} diff --git a/pysite/database.py b/pysite/database.py index 239a2fdc..78c4368a 100644 --- a/pysite/database.py +++ b/pysite/database.py @@ -1,12 +1,10 @@ # coding=utf-8 import logging import os - from typing import Any, Callable, Dict, Iterator, List, Optional, Union -from flask import abort - import rethinkdb +from flask import abort from rethinkdb.ast import RqlMethodQuery, Table, UserError from rethinkdb.net import DefaultConnection diff --git a/pysite/decorators.py b/pysite/decorators.py index 03d5e6b8..94239fbc 100644 --- a/pysite/decorators.py +++ b/pysite/decorators.py @@ -4,7 +4,6 @@ from functools import wraps from json import JSONDecodeError from flask import request - from schema import Schema, SchemaError from pysite.constants import ErrorCodes, ValidationTypes diff --git a/pysite/mixins.py b/pysite/mixins.py index 930a7eb7..059f871d 100644 --- a/pysite/mixins.py +++ b/pysite/mixins.py @@ -1,9 +1,7 @@ # coding=utf-8 -from _weakref import ref - from flask import Blueprint - from rethinkdb.ast import Table +from _weakref import ref from pysite.database import RethinkDB diff --git a/pysite/route_manager.py b/pysite/route_manager.py index 494dfbde..53b24def 100644 --- a/pysite/route_manager.py +++ b/pysite/route_manager.py @@ -5,7 +5,6 @@ import logging import os from flask import Blueprint, Flask - from flask_sockets import Sockets from pysite.base_route import APIView, BaseView, ErrorView, RouteView diff --git a/pysite/views/api/bot/user.py b/pysite/views/api/bot/user.py index f80bb826..c9686f56 100644 --- a/pysite/views/api/bot/user.py +++ b/pysite/views/api/bot/user.py @@ -1,7 +1,6 @@ # coding=utf-8 from flask import jsonify - from schema import Schema from pysite.base_route import APIView diff --git a/pysite/views/error_handlers/http_404.py b/pysite/views/error_handlers/http_404.py deleted file mode 100644 index 1d557d9b..00000000 --- a/pysite/views/error_handlers/http_404.py +++ /dev/null @@ -1,12 +0,0 @@ -# coding=utf-8 -from werkzeug.exceptions import NotFound - -from pysite.base_route import ErrorView - - -class Error404View(ErrorView): - name = "error_404" - error_code = 404 - - def get(self, error: NotFound): - return "replace me with a template, 404 not found", 404 diff --git a/pysite/views/error_handlers/http_4xx.py b/pysite/views/error_handlers/http_4xx.py new file mode 100644 index 00000000..1417c1f6 --- /dev/null +++ b/pysite/views/error_handlers/http_4xx.py @@ -0,0 +1,22 @@ +# coding=utf-8 +from flask import render_template, request +from werkzeug.exceptions import NotFound + +from pysite.base_route import ErrorView +from pysite.constants import ERROR_DESCRIPTIONS + + +class Error400View(ErrorView): + name = "error_4xx" + error_code = range(400, 430) + + def get(self, error: NotFound): + error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") + + return render_template("errors/error.html", code=error.code, req=request, error_title=error_desc, + error_message=error_desc + + " If you believe we have made a mistake, " + "please open an issue " + "on our GitHub (" + "https://github.com" + "/discord-python/site/issues)."), error.code diff --git a/pysite/views/error_handlers/http_5xx.py b/pysite/views/error_handlers/http_5xx.py index ed4d8d82..ecf4a35e 100644 --- a/pysite/views/error_handlers/http_5xx.py +++ b/pysite/views/error_handlers/http_5xx.py @@ -1,12 +1,25 @@ # coding=utf-8 +from flask import render_template, request from werkzeug.exceptions import HTTPException from pysite.base_route import ErrorView +from pysite.constants import ERROR_DESCRIPTIONS -class Error404View(ErrorView): +class Error500View(ErrorView): name = "error_5xx" error_code = range(500, 600) def get(self, error: HTTPException): - return "Internal server error. Please try again later!", error.code + error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") + + return render_template("errors/error.html", code=error.code, req=request, error_title=error_desc, + error_message="An error occured while " + "processing this " + "request, please try " + "again later. " + "If you believe we have made a mistake, " + "please open an issue " + "on our GitHub (" + "https://github.com" + "/discord-python/site/issues)."), error.code diff --git a/pysite/views/main/abort.py b/pysite/views/main/abort.py new file mode 100644 index 00000000..d9e3282f --- /dev/null +++ b/pysite/views/main/abort.py @@ -0,0 +1,12 @@ +# coding=utf-8 +from werkzeug.exceptions import InternalServerError + +from pysite.base_route import RouteView + + +class EasterEgg500(RouteView): + path = "/500" + name = "500" + + def get(self): + raise InternalServerError diff --git a/pysite/views/main/error.py b/pysite/views/main/error.py new file mode 100644 index 00000000..18c20c6e --- /dev/null +++ b/pysite/views/main/error.py @@ -0,0 +1,12 @@ +# coding=utf-8 +from flask import abort + +from pysite.base_route import RouteView + + +class ErrorView(RouteView): + path = "/error/<int:code>" + name = "error" + + def get(self, code): + return abort(code) diff --git a/pysite/views/tests/index.py b/pysite/views/tests/index.py index 78b7ef2e..3071bf0e 100644 --- a/pysite/views/tests/index.py +++ b/pysite/views/tests/index.py @@ -1,7 +1,6 @@ # coding=utf-8 from flask import jsonify - from schema import Schema from pysite.base_route import RouteView diff --git a/pysite/websockets.py b/pysite/websockets.py index fa1fd0eb..1e7960f7 100644 --- a/pysite/websockets.py +++ b/pysite/websockets.py @@ -1,6 +1,5 @@ # coding=utf-8 from flask import Blueprint - from geventwebsocket.websocket import WebSocket |