handler: improve error handling