diff --git a/CHANGES.rst b/CHANGES.rst
index 72b550b..195a2b5 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,6 +5,7 @@
 - Some minor doc fixes
 - Changed an edge case where `items` or `applications` response attributes could
   be `None` so that they are now always empty lists. (#6)
+- Updated error message and added JSON error message when a backend application can't be reached (#9) and when a resource can't be deleted (#10)
 
 0.4.0 (2015-07-10)
 ------------------
diff --git a/pyramid_urireferencer/models.py b/pyramid_urireferencer/models.py
index 067dd57..8ce334b 100644
--- a/pyramid_urireferencer/models.py
+++ b/pyramid_urireferencer/models.py
@@ -94,7 +94,7 @@ class ApplicationResponse:
             "success": self.success,
             "has_references": self.has_references,
             "count": self.count,
-            "items": [item.to_json() for item in self.items]
+            "items": [item.to_json() for item in self.items] if self.items else []
         }
 
 
diff --git a/pyramid_urireferencer/protected_resources.py b/pyramid_urireferencer/protected_resources.py
index db4556a..d54efaa 100644
--- a/pyramid_urireferencer/protected_resources.py
+++ b/pyramid_urireferencer/protected_resources.py
@@ -50,8 +50,8 @@ def protected_operation(fn):
                                     app_response.count,
                                     ', '.join([i.uri for i in app_response.items]))
                         response_json["errors"].append(error_string)
-                        response.json_body = response_json
-                        response.content_type = 'application/json'
+                    response.json_body = response_json
+                    response.content_type = 'application/json'
                 return response
             else:
                 raise HTTPConflict(
@@ -60,8 +60,26 @@ def protected_operation(fn):
                                    ', '.join([app_response.title for app_response in registery_response.applications
                                               if app_response.has_references])))
         elif not registery_response.success:
-            raise HTTPInternalServerError(
-                    detail="Urireferencer: Something went wrong while retrieving references of the uri {0}".format(uri))
+            if parent_object.request.headers.get("Accept", None) == "application/json":
+                response = Response()
+                response.status_code = 500
+                response_json = {
+                    "message": "Unable to verify the uri {0} is no longer being used.".format(uri),
+                    "errors": [],
+                    "registry_response": registery_response.to_json()
+                }
+                for app_response in registery_response.applications:
+                    if not app_response.success:
+                        response_json["errors"].append(
+                            "{}: Could not verify the uri is no longer being used.".format(app_response.uri))
+                response.json_body = response_json
+                response.content_type = 'application/json'
+                return response
+            else:
+                raise HTTPInternalServerError(
+                        detail="Urireferencer: Unable to verify the uri {0} is no longer being used. Could not verify with {1}".
+                            format(uri, ', '.join([app_response.uri for app_response
+                                                   in registery_response.applications if not app_response.success])))
         return fn(parent_object, *args, **kw)
 
     return advice

Error message when a backend application can't be reached
When a service is not reachable for the uriregistry.

AS IS:
HTTPInternalServerError: Urireferencer: Something went wrong while retrieving references of the uri https://id.erfgoed.net/besluiten/1

TO BE:
HTTP 503 Service Unavailable: Urireferencer: Something went wrong while retrieving references of the uri https://id.erfgoed.net/test/1. Application A not reachable. 

diff --git a/tests/test_protected_resources.py b/tests/test_protected_resources.py
index 1989235..81972ee 100644
--- a/tests/test_protected_resources.py
+++ b/tests/test_protected_resources.py
@@ -29,6 +29,18 @@ def get_app(nr):
     return a
 
 
+def get_app_500():
+    return ApplicationResponse(
+        title='App',
+        uri="https://dev-app.onroerenderfgoed.be/",
+        service_url="https://dev-app.onroerenderfgoed.be/references",
+        success=False,
+        has_references=None,
+        count=None,
+        items=None
+    )
+
+
 class DummyParent(object):
     def __init__(self):
         self.request = testing.DummyRequest()
@@ -96,7 +108,25 @@ class ProtectedTests(unittest.TestCase):
     def test_protected_operation_500(self, is_referenced_mock):
         dummy = DummyParent()
         is_referenced_mock.return_value = RegistryResponse('https://id.erfgoed.net/resources/1', False, None, None,
-                                                           None)
+                                                           [get_app_500()])
         self.assertRaises(HTTPInternalServerError, dummy.protected_dummy)
         is_referenced_call = is_referenced_mock.mock_calls[0]
         self.assertEqual('https://id.erfgoed.net/resources/1', is_referenced_call[1][0])
+
+    @patch('pyramid_urireferencer.protected_resources.pyramid_urireferencer.Referencer.is_referenced')
+    def test_protected_operation_500_json(self, is_referenced_mock):
+        dummy = DummyParent()
+        dummy.request.headers = {"Accept": "application/json"}
+        is_referenced_mock.return_value = RegistryResponse('https://id.erfgoed.net/resources/1', False, None, None,
+                                                           [get_app_500()])
+        res = dummy.protected_dummy()
+        self.assertEqual(500, res.status_code)
+        self.assertEqual(res.json_body["message"],
+                         "Unable to verify the uri https://id.erfgoed.net/resources/1 is no longer being used.")
+        self.assertListEqual(res.json_body["errors"],
+                             ["https://dev-app.onroerenderfgoed.be/: Could not verify the uri is no longer being used."])
+        self.assertEqual("application/json", res.content_type)
+
+        is_referenced_call = is_referenced_mock.mock_calls[0]
+        self.assertEqual('https://id.erfgoed.net/resources/1', is_referenced_call[1][0])
+

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov webtest httpretty coveralls mock
apt-get update apt-get install -y gcc
3.5
requirements.txt
py.test --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
beautifulsoup4==4.12.3
certifi==2021.5.30
coverage==6.2
coveralls==3.3.1
docopt==0.6.2
httpretty==1.1.4
importlib-metadata==4.8.3
iniconfig==1.1.1
mock==5.2.0
packaging==21.3
PasteDeploy==2.1.1
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pyramid==1.6.1
-e git+https://github.com/OnroerendErfgoed/pyramid_urireferencer.git@067293d191dc9dd4f7c2554f71bf0c730786a872#egg=pyramid_urireferencer
pytest==7.0.1
pytest-cov==4.0.0
repoze.lru==0.7
requests==2.9.1
soupsieve==2.3.2.post1
tomli==1.2.3
translationstring==1.4
typing_extensions==4.1.1
venusian==3.0.0
waitress==2.0.0
WebOb==1.8.9
WebTest==3.0.0
zipp==3.6.0
zope.deprecation==4.4.0
zope.interface==5.5.2

name: pyramid_urireferencer
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - beautifulsoup4==4.12.3
      - coverage==6.2
      - coveralls==3.3.1
      - docopt==0.6.2
      - httpretty==1.1.4
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - mock==5.2.0
      - packaging==21.3
      - pastedeploy==2.1.1
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pyramid==1.6.1
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - repoze-lru==0.7
      - requests==2.9.1
      - soupsieve==2.3.2.post1
      - tomli==1.2.3
      - translationstring==1.4
      - typing-extensions==4.1.1
      - venusian==3.0.0
      - waitress==2.0.0
      - webob==1.8.9
      - webtest==3.0.0
      - zipp==3.6.0
      - zope-deprecation==4.4.0
      - zope-interface==5.5.2
prefix: /opt/conda/envs/pyramid_urireferencer

tests/test_protected_resources.py::ProtectedTests::test_protected_operation_500_json
tests/test_protected_resources.py::ProtectedTests::test_protected_operation tests/test_protected_resources.py::ProtectedTests::test_protected_operation_409 tests/test_protected_resources.py::ProtectedTests::test_protected_operation_409_2 tests/test_protected_resources.py::ProtectedTests::test_protected_operation_409_json tests/test_protected_resources.py::ProtectedTests::test_protected_operation_500
pyramid_urireferencer/protected_resources.py pyramid_urireferencer/models.py CHANGES.rst
pyramid_urireferencer/protected_resources.py pyramid_urireferencer/models.py CHANGES.rst