diff --git a/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs b/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs index ed3b2830..04d534c0 100644 --- a/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs +++ b/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs @@ -16,14 +16,21 @@ public RemoteCommunicationService(ParlanceContext dbContext) public Credentials CredentialsHandler(string url, string usernameFromUrl, SupportedCredentialTypes types) { //TODO: Check number of retries - var key = _dbContext.SshKeys.First(); - - return new SshKeyMemoryCredentials + try { - Username = usernameFromUrl, - PublicKey = key.SshKeyContents, - PrivateKey = key.SshPrivateKeyContents - }; + var key = _dbContext.SshKeys.First(); + + return new SshKeyMemoryCredentials + { + Username = usernameFromUrl, + PublicKey = key.SshKeyContents, + PrivateKey = key.SshPrivateKeyContents + }; + } + catch (InvalidOperationException) + { + return new DefaultCredentials(); + } } public bool CertificateCheckHandler(Certificate certificate, bool valid, string host)