Skip to content

Commit

Permalink
Wrap connection exceptions in NpgsqlException
Browse files Browse the repository at this point in the history
Closes npgsql#901
  • Loading branch information
roji committed Jun 17, 2019
1 parent 4ebb237 commit 68147c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Npgsql/NpgsqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void Connect(NpgsqlTimeout timeout)
Log.Trace($"Failed to connect to {endpoint}", e);

if (i == endpoints.Length - 1)
throw;
throw new NpgsqlException("Exception while connecting", e);
}
}
}
Expand Down Expand Up @@ -737,7 +737,7 @@ await socket.ConnectAsync(endpoint)

if (i == endpoints.Length - 1)
{
throw;
throw new NpgsqlException("Exception while connecting", e);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/Npgsql.Tests/PoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ public void PhysicalOpenFailure()
using (var conn = new NpgsqlConnection(connString))
{
for (var i = 0; i < 1; i++)
Assert.That(() => conn.Open(), Throws.Exception.TypeOf<SocketException>());
Assert.That(() => conn.Open(), Throws.Exception
.TypeOf<NpgsqlException>()
.With.InnerException.TypeOf<SocketException>());
Assert.True(PoolManager.TryGetValue(connString, out var pool));
AssertPoolState(pool, 0, 0);
}
Expand Down

0 comments on commit 68147c4

Please sign in to comment.