improved the output message for rpc exception and removed some duplicated code