Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit d713436

Browse files
Ihar YakimushIhar Yakimush
authored andcommitted
response stream unable to write exception
1 parent c316aea commit d713436

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Commmunity.AspNetCore.ExceptionHandling/Logs/LogHandlerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class LogHandlerOptions<TException> : IOptions<LogHandlerOptions<TExcepti
3535
/// <summary>
3636
/// Factory for log category. By default "Commmunity.AspNetCore.ExceptionHandling" will be used.
3737
/// </summary>
38-
public Func<HttpContext,Exception,string> Category { get; set; }
38+
public Func<HttpContext, Exception, string> Category { get; set; }
3939

4040
/// <summary>
4141
/// Factory for <see cref="LogLevel"/> log level. By default <see cref="LogLevel.Error"/> error will be used. In case of <see cref="LogLevel.None"/> none log entry will be skipped.

Commmunity.AspNetCore.ExceptionHandling/Response/RawResponseExceptionHandler.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ public static Task SetBody(HttpContext context, TException exception, Func<HttpR
9494
if (stream.CanSeek)
9595
{
9696
stream.Seek(0, SeekOrigin.Begin);
97-
//stream.SetLength(0);
97+
stream.SetLength(0);
9898
}
9999

100100
if (stream.CanWrite)
101101
{
102-
StreamWriter writer = new StreamWriter(stream,Encoding.UTF8,1024, true);
102+
StreamWriter writer = new StreamWriter(stream, Encoding.UTF8, 1024, true);
103103

104104
return settings(context.Request, writer, exception);
105105
}
106+
else
107+
{
108+
throw new InvalidOperationException("Unable to write to response stream");
109+
}
106110
}
107111

108112
return Task.CompletedTask;

0 commit comments

Comments
 (0)