Skip to content

Commit

Permalink
Bugfix: get function would throw an error when doc wasn't found rat…
Browse files Browse the repository at this point in the history
…her than returning None as expected.

Signed-off-by: Joshua Harms <[email protected]>
  • Loading branch information
nozzlegear committed Feb 6, 2018
1 parent 5795041 commit 75c1e1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Davenport.Fsharp.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyTestClass> (Guid.NewGuid().ToString()) None client

Expect.isNone docResult "DocResult should be None"
}

testCaseAsync "Counts docs" <| async {
do! create<MyTestClass> defaultRecord client |> Async.Ignore

Expand Down
2 changes: 1 addition & 1 deletion Davenport.Fsharp/Davenport.Fsharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Davenport.Fsharp</AssemblyName>
<RootNamespace>Davenport.Fsharp</RootNamespace>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
</PropertyGroup>
<PropertyGroup>
<Description>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#.</Description>
Expand Down
12 changes: 9 additions & 3 deletions Davenport.Fsharp/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 75c1e1b

Please sign in to comment.