This function factors out the logic of extracting an error message from a `Response` object into a reusable utility function. This will allow other pages to use the same logic without duplicating it.