Fix npe when unwrapping optional. (#12882)

This commit is contained in:
Marcus Handte 2022-07-19 13:11:11 +02:00 committed by GitHub
parent f176716a61
commit 8fded5c47e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -353,8 +353,8 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
default:
guard let data = data, !data.isEmpty else {
if T.self is ExpressibleByNilLiteral.Type {
completion(.success(Response(response: httpResponse, body: Optional<T>.none as! T)))
if let E = T.self as? ExpressibleByNilLiteral.Type {
completion(.success(Response(response: httpResponse, body: E.init(nilLiteral: ()) as! T)))
} else {
completion(.failure(ErrorResponse.error(httpResponse.statusCode, nil, response, DecodableRequestBuilderError.emptyDataResponse)))
}