Skip to content

Commit

Permalink
Improve error message when HttpContent is disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
Christer van der Meeren committed Sep 13, 2024
1 parent 94216d4 commit 4d0a23b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 4 additions & 10 deletions src/Faqt.Tests/Formatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ Value: |-
x.Content <- JsonContent.Create({| a = "foo"; b = null; c = [ 3; 4 ] |})
x.Dispose()
x.Should().FailWith("Value", x)
|> assertExnMsgWildcard
|> assertExnMsg
"""
Subject: x
Should: FailWith
Expand All @@ -892,10 +892,7 @@ Value: |-
Foo: Baz
Foo: Bar
An exception occured trying to get the content:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.Json.JsonContent'.
at *
[content is disposed and cannot be read]
"""


Expand Down Expand Up @@ -995,7 +992,7 @@ Value: |-
x.Content <- JsonContent.Create({| a = "foo"; b = null; c = [ 3; 4 ] |})
x.Dispose()
x.Should().FailWith("Value", x)
|> assertExnMsgWildcard
|> assertExnMsg
"""
Subject: x
Should: FailWith
Expand All @@ -1005,10 +1002,7 @@ Value: |-
Foo: Baz
Foo: Bar
An exception occured trying to get the content:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.Json.JsonContent'.
at *
[content is disposed and cannot be read]
"""


Expand Down
6 changes: 5 additions & 1 deletion src/Faqt/Formatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ module internal HttpContent =
|> String.truncate $"\n[content truncated after %i{maxLength} characters]" maxLength

sb.AppendLine().AppendLine().Append(strContent) |> ignore
with ex ->
with
| :? ObjectDisposedException ->
sb.AppendLine().AppendLine().Append("[content is disposed and cannot be read]")
|> ignore
| ex ->
sb
.AppendLine()
.AppendLine()
Expand Down

0 comments on commit 4d0a23b

Please sign in to comment.