Check if error is set and cast to array