Rewrite testcases for error handler

Now they actually test desired behaviour, not random side effects of the
code.