fix tests and add correct error handler