[Foundation] Do expose server errors. (#9017)
Creating a good API is hard. The delegate DOES return two different errors. 1. Client errors in the error variable in the delegate method. 2. Server errros in the error in the task in the delegate method. We need to expose both of them to the user in case there is an issue in any of them. An exception should be thrown ig any is not null. PD: As per apple docs: > The only errors your delegate receives through the error parameter are > client-side errors, such as being unable to resolve the hostname or > connect to the host. To check for server-side errors, inspect the > response property of the task parameter received by this callback. Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
This commit is contained in:
Родитель
78a5ae5b98
Коммит
410de802d6
|
@ -650,6 +650,7 @@ namespace Foundation {
|
|||
public override void DidCompleteWithError (NSUrlSession session, NSUrlSessionTask task, NSError error)
|
||||
{
|
||||
var inflight = GetInflightData (task);
|
||||
var serverError = task.Error;
|
||||
|
||||
// this can happen if the HTTP request times out and it is removed as part of the cancellation process
|
||||
if (inflight != null) {
|
||||
|
@ -657,12 +658,12 @@ namespace Foundation {
|
|||
inflight.Stream.TrySetReceivedAllData ();
|
||||
|
||||
// send the error or send the response back
|
||||
if (error != null) {
|
||||
if (error != null || serverError != null) {
|
||||
// got an error, cancel the stream operatios before we do anything
|
||||
inflight.CancellationTokenSource.Cancel ();
|
||||
inflight.Errored = true;
|
||||
|
||||
var exc = inflight.Exception ?? createExceptionForNSError (error);
|
||||
var exc = inflight.Exception ?? createExceptionForNSError (error ?? serverError); // client errors wont happen if we get server errors
|
||||
inflight.CompletionSource.TrySetException (exc);
|
||||
inflight.Stream.TrySetException (exc);
|
||||
} else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче