Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/exception.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from typing import Dict, Optional | from typing import Dict, Optional | ||||
from django.db.utils import OperationalError | from django.db.utils import OperationalError | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from rest_framework.exceptions import APIException | from rest_framework.exceptions import APIException | ||||
from rest_framework.views import exception_handler | |||||
def custom_exception_handler( | def custom_exception_handler( | ||||
exc: APIException, context: Dict | exc: APIException, context: Dict | ||||
) -> Optional[HttpResponse]: | ) -> Optional[HttpResponse]: | ||||
"""Custom deposit exception handler to ensure consistent xml output | """Custom deposit exception handler to ensure consistent xml output | ||||
""" | """ | ||||
anlambert: why moving that import here ? | |||||
Done Inline Actionsone test about this failed otherwise ardumont: one test about this failed otherwise
(i don't recall exactly why) | |||||
from rest_framework.views import exception_handler | |||||
# drf's default exception handler first, to get the standard error response | # drf's default exception handler first, to get the standard error response | ||||
response = exception_handler(exc, context) | response = exception_handler(exc, context) | ||||
if isinstance(exc, OperationalError): | if isinstance(exc, OperationalError): | ||||
status = "Database backend maintenance" | status = "Database backend maintenance" | ||||
detail = "Service temporarily unavailable, try again later." | detail = "Service temporarily unavailable, try again later." | ||||
data = f"""<?xml version="1.0" encoding="utf-8"?> | data = f"""<?xml version="1.0" encoding="utf-8"?> | ||||
<sword:error xmlns="http://www.w3.org/2005/Atom" | <sword:error xmlns="http://www.w3.org/2005/Atom" | ||||
Show All 10 Lines |
why moving that import here ?