Search⌘ K
AI Features

Error Management in a Use Case

Understand how to implement robust error management and request validation in a use case within clean architecture. Learn to handle exceptions, update API endpoints, and perform integration tests to ensure external system compatibility using Flask in Python.

Now that our implementation of requests and responses is complete, we can implement the final version of our use case. In our program, a proper validation of the incoming request for the room_list_use_case function is still missing. So, it doesn’t yet return a suitable response when something goes wrong.

Update test case

The test_room_list_without_parameters test must match the new API, so we add filters=None to assert_called_with in the code below:

Python 3.5
def test_room_list_without_parameters(domain_rooms):
repo = mock.Mock()
repo.list.return_value = domain_rooms
request = build_room_list_request()
response = room_list_use_case(repo, request)
assert bool(response) is True
repo.list.assert_called_with(filters=None)
assert response.value == domain_rooms

There are three new tests that we can add to check the behavior of the use case when filters are not None. The first test checks if ...