Pulled the test to a separate method
Minor code improvements

Extracted list(error)[0] to a variable.
Added a removed trailing comma.