[swift6][alamofire] Report -1, not 500, when there is no HTTP response

Merged
SP
18d ago
+24-21

Fixes #25187.

  • response?.statusCode ?? 500 becomes ?? -1 in all five alamofire failure paths, matching the urlsession library's -1 for transport errors. When there is a response, its real status code is reported as before.
  • A failed file download reports the response's status code (or -1) and Alamofire's underlying error, instead of 400 + DownloadException.responseFailed.

Behaviour change: callers that check for 500 to detect any failure will no longer see network failures there. They should check for -1, or inspect the underlying AFError/URLError, which is unchanged.

Verified downstream with an offline URLProtocol stub: an Alamofire request without a response now reports -1 with AFError wrapping URLError.notConnectedToInternet. The alamofireLibrary sample builds.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/swift6*.yaml || exit
    
    Commit all changed files.
  • @mention the technical committee: @jgavris @ehyche @Edubits @jaz-ah @4brunu @dydus0x14

Summary by cubic

Reports -1 instead of 500 when an Alamofire failure has no HTTP response, matching how the urlsession library reports transport errors like offline, timeout, and cancellation. A failed file download now reports the response's status code (or -1) with the underlying Alamofire error instead of 400 with DownloadException.responseFailed.

Callers that check for 500 to detect any failure will no longer see network failures there; they should check for -1 or inspect the underlying AFError/URLError, which is unchanged.