Is it possible to see the response message coming from the server and if so could to you post an example?
I am trying to use this to have on spot where I place the "error" toast so I need to be able to see when the request returns the error.
Thanks!
One solution is to change the SendAsync method to:
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = null;
try
{
BeforeSend?.Invoke(this, request);
response = await (SendAsyncMethod.Invoke(Handler, new object[] { request, cancellationToken }) as Task<HttpResponseMessage>);
return response;
}
finally
{
AfterSend?.Invoke(this, response);
}
}
and the eventhandlers to
/// <summary>
/// Occurs before a HTTP request sending.
/// </summary>
public event EventHandler<HttpRequestMessage> BeforeSend;
/// <summary>
/// Occurs after received a response of a HTTP request. (include it wasn't succeeded.)
/// </summary>
public event EventHandler<HttpResponseMessage> AfterSend;
I took this suggestion. Sorta seems that's how it should be in the first place. Makes this interceptor significantly more useful, unless I am not understanding the usefulness of EventArgs e
Thank you for nice feedback! 馃憤
I published "Blazor WebAssembly (client-side) HttpClient Interceptor" v.6.1.0 that include the new feature suggested by @khamang !
See also: https://github.com/jsakamoto/Toolbelt.Blazor.HttpClientInterceptor/#the-arguments-of-event-handler
So this should be fixed? I still get an error if I want to access the response content in the AfterSend.
It says in the Service that makes the http.PostAsync cant access the body because it is locked
@TheSwerik Thank you for your reporting.
So this should be fixed? I still get an error ...
This thread is not an error report, this is a new feature proposal thread.
I never knew it has a problem that you reported now.
I'll try to reproduce that problem later, and I'll try to fix it if I could reproduce it.
Oh I thought this fits here, I will create a new and more detailed issue
@TheSwerik Thanks!