Skip to content

Commit a877807

Browse files
author
n9
committed
FindAsync do to use exception in case of non-existent document
1 parent bc266cb commit a877807

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/CouchDB.Driver/CouchDatabase.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using CouchDB.Driver.Options;
2222
using CouchDB.Driver.Query;
2323
using Newtonsoft.Json;
24+
using System.Net;
2425

2526
namespace CouchDB.Driver
2627
{
@@ -66,28 +67,27 @@ internal CouchDatabase(IFlurlClient flurlClient, CouchOptions options, QueryCont
6667
/// <inheritdoc />
6768
public async Task<TSource?> FindAsync(string docId, bool withConflicts = false, CancellationToken cancellationToken = default)
6869
{
69-
try
70-
{
71-
IFlurlRequest request = NewRequest()
72-
.AppendPathSegment(docId);
70+
IFlurlRequest request = NewRequest()
71+
.AppendPathSegment(docId);
7372

74-
if (withConflicts)
75-
{
76-
request = request.SetQueryParam("conflicts", true);
77-
}
73+
if (withConflicts)
74+
{
75+
request = request.SetQueryParam("conflicts", true);
76+
}
7877

79-
TSource document = await request
80-
.GetJsonAsync<TSource>(cancellationToken)
81-
.SendRequestAsync()
82-
.ConfigureAwait(false);
78+
TSource document = await request
79+
.AllowHttpStatus(HttpStatusCode.NotFound)
80+
.GetJsonAsync<TSource>(cancellationToken)
81+
.SendRequestAsync()
82+
.ConfigureAwait(false);
8383

84-
InitAttachments(document);
85-
return document;
86-
}
87-
catch (CouchNotFoundException)
84+
if (document.Id == null) // hack before Flurl v3
8885
{
8986
return null;
9087
}
88+
89+
InitAttachments(document);
90+
return document;
9191
}
9292

9393
/// <inheritdoc />

0 commit comments

Comments
 (0)