router: improve error checking