Closed raV720 closed 1 year ago
Is it possible to do it with your library?
For sure
demo code :
TusPatchRequestOption tusPatchRequestOption = new TusPatchRequestOption
{
// others codes
// If it failed Upload, client will invoke OnFailedAsync method
OnFailedAsync = x =>
{
Console.WriteLine($"error: {x.Exception.Message}");
if (x.OriginHttpRequestMessage is not null)
{
//log httpRequest
}
if (x.OriginResponseMessage is not null)
{
//log response
}
return Task.CompletedTask;
}
};
var tusPatchResp = await tusClient.TusPatchAsync(tusPatchRequestOption, CancellationToken.None);
I don't know how i missed it. Thank you
The response is not available when there is an error (not success status code) on the TusHeadAsync, TusOptionAsync and TusDeleteAsync
I suggest that you get that exception with try catch code, and then you can know why there is an error.
The exception has very limited information about what happened and this information is included in Message string. Parsing message is not a good way to detect for example status code.
Netstandard 2.0 does not have such property. And still it is very limited if available. IMO the response should be accessible in some way.
Can you show me an exception, I may resolve your problem
"InnerException": { "HResult": -2146233088, "Message": "Response status code does not indicate success: 409 (Conflict).", "Source": "System.Net.Http", "Type": "System.Net.Http.HttpRequestException" },
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at BirdMessenger.HttpClientExtension.
Which method did throw an exception?
It is so weird, I think HeadMethod never gets an 409 exception, You can refer to https://tus.io/protocols/resumable-upload#concatenation
The 409 status is only an example of response which is not possible to handle. Other statuses are also not possible to verify.
According to the 409 Conflict it is known issue with Kestrel selfhost and tusdotnet implementation: https://github.com/tusdotnet/tusdotnet/issues/204
OK, I understand. If you do not know how to handle an exceptional status, I can handle it for you. If you want to log which exceptional status with codes, I suggest you run your code on net core runtime.
By the way, I want to know why do want to detect the server response status code, Because I think logging exceptional Messages is enough
The status code is required to act accordingly when it is 409 or 404 or 401 or other status (maybe 5**). And whether to retry sending file or stop retrying if error is permanent.
Okay, I see. I will think about that.
I suggest retrying invoking method as long as there is an exception and you set Max retry times
Some exceptions (status codes) are permanent and it is pointless to repeat the request. Anyway thank you for help and time.
Some exceptions (status codes) are permanent and it is pointless to repeat the request.
Yep, I totally agree. You can avoid that by setting Max retry times at present.
Anyway thank you for help and time.
You are welcome, I will handle your problem by throwing a custom exception which contains any information you want
@raV720
I will handle your problem by throwing a custom exception which contains any information you want
I have been released v3.1.2
I would like to detect when server responses with 409 or 404 or other status code and act accordingly. Is it possible to do it with your library? As I can see your library throws HttpRequestException but it does not allow to get status code.