Refactor rpc handler check
Better rpc error handling