ra0o0f / arangoclient.net

ArangoDB .NET Client with LINQ support
Apache License 2.0
99 stars 37 forks source link

ArangoServerException not throw when db unavailable #117

Open imtrobin opened 5 years ago

imtrobin commented 5 years ago

Hi, I'm trying out arangodbclient on a new sample.

  1. After I call CreateWithSetting, how do I check that the db connection is valid? I don't see a valid connection or check.

  2. CreateDatabase will throw but it is throwing System.Exception. I would expect ArangoServerException so I can catch it and deal appropriately. I see WaitSynchronizer does not do that, why not throw as ArangoServerException?

ArangoDatabase.ChangeSetting(s =>
{
    s.Database                             = "TutorialDotNet";
    s.Url                                  = "http://localhost:8529";
    // you can set other settings if you need
    s.Credential                           = new NetworkCredential("root", "123456");
    s.SystemDatabaseCredential             = new NetworkCredential("root", "123456");
    s.WaitForSync                          = true;
    s.Serialization.SerializeEnumAsInteger = false;
});

IArangoDatabase db = ArangoDatabase.CreateWithSetting ();

// not working, How do I detect if connection is valid
 if (null == db)
    ReportError ("DB Null");

// this thorws System.Exception, I would expect ArangobServerException
db.CreateDatabase ("TutorialDotNet");
ra0o0f commented 5 years ago

@imtrobin

  1. There is no db connection check on CreateWithSetting. You wont know if your connection settings are valid until the first request is sent. you can call db.CurrentDatabaseInformation() to make a small request to check for connection validity.

  2. ArangoServerException will only be raised for database server errors, not the client. the reason for this was to separate server and client errors. you can take a look at ArangoDB Error Codes. unfortunately you can't catch a specific Exception class that corresponds to client errors

imtrobin commented 5 years ago

Thanks for the quick reply.

Even though it is a httpclient call internally on client, I would think its better to have a ArrangoException class that we can trap properly. ArangoServerException can subclass fromt that