Make error handler a function

Signed-off-by: Michal Čihař <michal@cihar.com>