diff --git a/Davenport.Fsharp.Tests/Tests.fs b/Davenport.Fsharp.Tests/Tests.fs index b0597fc..e87f98c 100644 --- a/Davenport.Fsharp.Tests/Tests.fs +++ b/Davenport.Fsharp.Tests/Tests.fs @@ -133,6 +133,12 @@ let tests = Expect.equal defaultRecord.Baz doc.Baz "" } + ftestCaseAsync "Returns None for dogs that don't exist" <| async { + let! docResult = get (Guid.NewGuid().ToString()) None client + + Expect.isNone docResult "DocResult should be None" + } + testCaseAsync "Counts docs" <| async { do! create defaultRecord client |> Async.Ignore diff --git a/Davenport.Fsharp/Davenport.Fsharp.fsproj b/Davenport.Fsharp/Davenport.Fsharp.fsproj index 67f3c49..a490b46 100644 --- a/Davenport.Fsharp/Davenport.Fsharp.fsproj +++ b/Davenport.Fsharp/Davenport.Fsharp.fsproj @@ -4,7 +4,7 @@ netstandard2.0 Davenport.Fsharp Davenport.Fsharp - 1.1.0 + 1.1.1 Davenport is a CouchDB client for simplifying common tasks like get, list, create, update and delete. This package wraps the original C# package, making it much more friendly to the functional programming style of F#. diff --git a/Davenport.Fsharp/Library.fs b/Davenport.Fsharp/Library.fs index 446c04a..c4f1481 100644 --- a/Davenport.Fsharp/Library.fs +++ b/Davenport.Fsharp/Library.fs @@ -113,6 +113,12 @@ let private convertPostPutCopyResponse (r: PostPutCopyResponse) = Rev = r.Rev Ok = Option.ofNullable r.Ok |> Option.defaultValue false } +let rec private findDavenportExceptionOrRaise (exn: Exception) = + match exn with + | :? System.AggregateException as exn -> findDavenportExceptionOrRaise exn.InnerException + | :? Davenport.Infrastructure.DavenportException as exn -> exn + | _ -> raise exn + let asyncMap (fn: 't -> 'u) task = async { let! result = task @@ -276,9 +282,9 @@ let get<'doctype> id (rev: string option) props = async { match doc with | Choice1Of2 doc -> Option.get doc.Data |> Some // We want this to fail if, for some reason, the jsonconverter was unable to convert FsDoc.Data | Choice2Of2 exn -> - match exn with - | :? Davenport.Infrastructure.DavenportException as exn when exn.StatusCode = 404 -> None - | _ -> raise exn + match findDavenportExceptionOrRaise exn with + | exn when exn.StatusCode = 404 -> None + | exn -> raise exn } /// Lists all documents on the database.