-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.py
More file actions
59 lines (46 loc) · 2.31 KB
/
Copy patherrors.py
File metadata and controls
59 lines (46 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from flask import jsonify, render_template, request
from requests import HTTPError
from werkzeug.exceptions import HTTPException
import sentry_sdk
from providers.exceptions import *
def error_response(code, name, message):
if request.path.startswith("/api/"):
return jsonify({
"success": False,
"error": {
"code": code,
"name": name,
"message": message
}
}), code
return render_template(
"error.html",
code=code,
name=name,
description=message,
), code
def register_error_handlers(app):
@app.errorhandler(HTTPException)
def handle_exception(e):
return error_response(e.code, e.name, e.description)
@app.errorhandler(HTTPError)
def handle_api_exception(e):
return error_response(e.response.status_code, e.response.reason, e.response.reason)
@app.errorhandler(DataDomeCookieExpiredError)
def handle_datadome_exception(e):
return error_response(503, "Service Unavailable", "The service is temporarily unavailable due to an expired DataDome token.")
@app.errorhandler(OuestFranceDisabledException)
def handle_ouestfrance_disabled_exception(e):
return error_response(501, "Not Implemented", "Ouest-France is disabled because the <code>OUESTFRANCE_REFRESH_TOKEN</code> environment variable is not set.")
@app.errorhandler(OuestFranceMissingSubscriptionException)
def handle_ouestfrance_missingsubscription_exception(e):
return error_response(402, "Payment Required", "The Ouest-France account does not has any active subscription.")
@app.errorhandler(MediapartDisabledException)
def handle_mediapart_disabled_exception(e):
return error_response(501, "Not Implemented", "Mediapart is disabled because the <code>PIERREVIVES_USERNAME</code> or <code>PIERREVIVES_PASSWORD</code> environment variable is not set.")
@app.errorhandler(MediapartInvalidLogin)
def handle_mediapart_invalidlogin_exception(e):
return error_response(402, "Payment Required", "The Mediapart account does not has any active subscription.")
@app.errorhandler(NotImplementedError)
def handle_notimplemented_exception(e):
return error_response(501, "Not Implemented", "This page isn't implemented yet")