Remove duplicate code in store_response_errors and store_metadata