borchero / Squid

Declarative and Reactive Networking for Swift.
https://squid.borchero.com
MIT License
71 stars 6 forks source link

Not receiving completion for 401 Unauthorize #5

Closed imyrvold closed 4 years ago

imyrvold commented 4 years ago

`

func create(roleName: String, claims: [Claim]) {
        self.cancellables = []

    let request = RoleCreateRequest(name: roleName, claims: claims)
    let response = request.schedule(with: service)

    response
        .print("role")
        .receive(on: RunLoop.main)
        .sink(receiveCompletion: { completion in
            switch completion {
            case .failure(let error):
                switch error {
                case .requestFailed(statusCode: 401, response: _):
                    self.manager.user = LoginResponse.empty
                default:
                    print("RolesStore create error:", error.localizedDescription)
                }
            case .finished:
                print("RolesStore create finished")
            }
        }, receiveValue: { role in
            self.roles.append(role)
        })
        .store(in: &cancellables)
}

`

I have no problem receiving value in the response, but when the token expires, I am not hitting the completion .failure. Here is the log when receiving 401:

role: receive subscription: (Filter) role: request unlimited [Squid]
[Squid] Scheduled request RoleCreateRequest with identifier 5: [Squid] - Method: POST [Squid] - Url: http://192.168.100.9:3000/api/v1/roles [Squid] - Headers: Authorization => Bearer%20eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1Y2Q1NGZmYmYzM2M2NzAwMjMzMDdiZGYiLCJyb2xlIjoiNWM2YmUzYWM3MTBkYjMyYTljNzdhMTJhIiwiaWF0IjoxNTgwNjIwNDEzLCJleHAiOjE1ODA2MjA0NzMsImF1ZCI6Imh0dHA6Ly9hcGkvdjEvcHJvdGVjdGVkIiwiaXNzIjoiaHR0cHM6Ly9hdml0ZWxsLm5vIiwic3ViIjoiYXZpdGVsbEBhdml0ZWxsLm5vIn0.FPJEARQJekgnQOUXH7XnYWe3OPjPD487f97g33a_mziO22j3QmqPRaldbOEKGdSoDXr0_4GeVDK5Kg6POGhFsw [Squid] Content-Type => application/json [Squid] - Body: { [Squid] "name" : "Splittegal", [Squid] "claims" : [ [Squid] { [Squid] "_id" : "5ce56067e242d4f812286013", [Squid] "name" : "appearance.read" [Squid] }, [Squid] { [Squid] "_id" : "5cd9488e710db3496cad2f13", [Squid] "name" : "building.kristiansand" [Squid] }, [Squid] { [Squid] "_id" : "5da81ce676ce794950a29a22", [Squid] "name" : "building.luftslottet" [Squid] } [Squid] ] [Squid] } [Squid]
[Squid]
[Squid] Finished request RoleCreateRequest with identifier 5: [Squid] - Status: 401 [Squid] - Headers: Connection => keep-alive [Squid] Content-Length => 12 [Squid] Content-Type => text/plain; charset=utf-8 [Squid] Date => Sun, 02 Feb 2020 05:14:51 GMT [Squid] Strict-Transport-Security => max-age=15552000; includeSubDomains [Squid] Vary => Origin [Squid] X-Content-Type-Options => nosniff [Squid] X-DNS-Prefetch-Control => off [Squid] X-Download-Options => noopen [Squid] X-Frame-Options => SAMEORIGIN [Squid] X-XSS-Protection => 1; mode=block [Squid] - Body: <12 bytes> [Squid]
KeyChain load SecureStore getValue [Squid]
[Squid] Scheduled request TokenRequest with identifier 6: [Squid] - Method: POST [Squid] - Url: https://192.168.100.9:3000/api/v1/login [Squid] - Headers:
Content-Type => application/json [Squid] - Body: { [Squid] "refresh_token" : "" [Squid] } [Squid]
2020-02-02 06:14:51.426697+0100 DuncanIdaho[2572:1247962] [BoringSSL] boringssl_context_handle_fatal_alert(1872) [C6:2][0x102ee5780] write alert, level: fatal, description: protocol version 2020-02-02 06:14:51.427256+0100 DuncanIdaho[2572:1247962] [BoringSSL] boringssl_context_error_print(1862) boringssl ctx 0x281a03d50: 4367252696:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242: 2020-02-02 06:14:51.434045+0100 DuncanIdaho[2572:1247962] [BoringSSL] boringssl_session_handshake_error_print(111) [C6:2][0x102ee5780] 4367252696:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242: 2020-02-02 06:14:51.434510+0100 DuncanIdaho[2572:1247962] [BoringSSL] nw_protocol_boringssl_handshake_negotiate_proceed(726) [C6:2][0x102ee5780] handshake failed at state 12288 2020-02-02 06:14:51.435847+0100 DuncanIdaho[2572:1247962] [] tcp_input [C6:3] flags=[R] seq=1341546743, ack=0, win=0 state=LAST_ACK rcv_nxt=1341546743, snd_una=3618034709 2020-02-02 06:14:51.436225+0100 DuncanIdaho[2572:1247962] Connection 6: received failure notification 2020-02-02 06:14:51.436471+0100 DuncanIdaho[2572:1247962] Connection 6: failed to connect 3:-9858, reason -1 2020-02-02 06:14:51.436512+0100 DuncanIdaho[2572:1247962] Connection 6: encountered error(3:-9858) 2020-02-02 06:14:51.449717+0100 DuncanIdaho[2572:1247962] [BoringSSL] boringssl_context_handle_fatal_alert(1872) [C7:2][0x1044f16e0] write alert, level: fatal, description: protocol version 2020-02-02 06:14:51.449976+0100 DuncanIdaho[2572:1247962] [BoringSSL] boringssl_context_error_print(1862) boringssl ctx 0x281a39770: 4367252696:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242: 2020-02-02 06:14:51.450736+0100 DuncanIdaho[2572:1247962] [BoringSSL] boringssl_session_handshake_error_print(111) [C7:2][0x1044f16e0] 4367252696:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242: 2020-02-02 06:14:51.450788+0100 DuncanIdaho[2572:1247962] [BoringSSL] nw_protocol_boringssl_handshake_negotiate_proceed(726) [C7:2][0x1044f16e0] handshake failed at state 12288 2020-02-02 06:14:51.451739+0100 DuncanIdaho[2572:1247962] Connection 7: received failure notification 2020-02-02 06:14:51.451929+0100 DuncanIdaho[2572:1247962] Connection 7: failed to connect 3:-9858, reason -1 2020-02-02 06:14:51.451967+0100 DuncanIdaho[2572:1247962] Connection 7: encountered error(3:-9858) 2020-02-02 06:14:51.454251+0100 DuncanIdaho[2572:1247962] [] tcp_input [C7:3] flags=[R] seq=55613446, ack=0, win=0 state=LAST_ACK rcv_nxt=55613446, snd_una=2297212123 2020-02-02 06:14:51.454620+0100 DuncanIdaho[2572:1247962] [] tcp_input [C7:3] flags=[R] seq=55613446, ack=0, win=0 state=CLOSED rcv_nxt=55613446, snd_una=2297212123 2020-02-02 06:14:51.464957+0100 DuncanIdaho[2572:1248179] [BoringSSL] boringssl_context_handle_fatal_alert(1872) [C8:2][0x102ee58f0] write alert, level: fatal, description: protocol version 2020-02-02 06:14:51.465033+0100 DuncanIdaho[2572:1248179] [BoringSSL] boringssl_context_error_print(1862) boringssl ctx 0x281a03d50: 4344147880:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242: 2020-02-02 06:14:51.465445+0100 DuncanIdaho[2572:1248179] [BoringSSL] boringssl_session_handshake_error_print(111) [C8:2][0x102ee58f0] 4344147880:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242: 2020-02-02 06:14:51.465501+0100 DuncanIdaho[2572:1248179] [BoringSSL] nw_protocol_boringssl_handshake_negotiate_proceed(726) [C8:2][0x102ee58f0] handshake failed at state 12288 2020-02-02 06:14:51.467352+0100 DuncanIdaho[2572:1248179] [] tcp_input [C8:3] flags=[R] seq=2124226899, ack=0, win=0 state=LAST_ACK rcv_nxt=2124226899, snd_una=3091635292 2020-02-02 06:14:51.467565+0100 DuncanIdaho[2572:1248179] Connection 8: received failure notification 2020-02-02 06:14:51.467845+0100 DuncanIdaho[2572:1248179] Connection 8: failed to connect 3:-9858, reason -1 2020-02-02 06:14:51.467882+0100 DuncanIdaho[2572:1248179] Connection 8: encountered error(3:-9858) 2020-02-02 06:14:51.470137+0100 DuncanIdaho[2572:1248179] Task .<8> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9858]) 2020-02-02 06:14:51.470705+0100 DuncanIdaho[2572:1248179] [] tcp_input [C8:3] flags=[R] seq=2124226899, ack=0, win=0 state=CLOSED rcv_nxt=2124226899, snd_una=3091635292 2020-02-02 06:14:51.474155+0100 DuncanIdaho[2572:1248599] Task .<8> finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://192.168.100.9:3000/api/v1/login, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask .<8>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalUploadTask .<8>" ), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://192.168.100.9:3000/api/v1/login, NSUnderlyingError=0x281711170 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858} [Squid]
[Squid] Finished request TokenRequest with identifier 6: [Squid] - Unknown error: unknown(Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://192.168.100.9:3000/api/v1/login, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask .<8>, _NSURLErrorRelatedURLSessionTaskErrorKey=( [Squid] "LocalUploadTask .<8>" [Squid] ), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://192.168.100.9:3000/api/v1/login, NSUnderlyingError=0x281711170 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858}) [Squid]

borchero commented 4 years ago

Which version of Squid is this? I can't really reproduce this error with version 1.1.8.

imyrvold commented 4 years ago

It was 1.1.0, but now I tried "Update to Latest Package Versions" in Xcode, and then I got Swift Package Dependencies Squid 1.1.9. And now it works, the switch case .requestFailed(statusCode: 401 was executed as it should. Thanks!