diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 1671647..c1d0f1b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -3,12 +3,12 @@ name: ci on: push: branches: [ master, main ] - tags: [ '[1-9]+.[0-9]+.[0-9]+*' ] paths-ignore: - '**.md' pull_request: paths-ignore: - '**.md' + release: workflow_dispatch: repository_dispatch: @@ -151,7 +151,7 @@ jobs: release: name: Release - if: startsWith(github.ref, 'refs/tags') + if: github.event_name == 'release' needs: samples runs-on: macOS-latest steps: diff --git a/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift b/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift index db9c07b..67fcef0 100644 --- a/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift +++ b/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift @@ -395,7 +395,7 @@ class HCaptchaWebViewManager__Tests: XCTestCase { exp2.fulfill() } - XCTAssertEqual(result1?.error, .wrongMessageFormat) + XCTAssertEqual(result1?.error, .sessionTimeout) // Resets and tries again let exp3 = expectation(description: "validates after reset") @@ -435,7 +435,7 @@ class HCaptchaWebViewManager__Tests: XCTestCase { switch event { case .error: XCTAssertEqual(.error, event) - XCTAssertEqual(HCaptchaError.wrongMessageFormat, error as? HCaptchaError) + XCTAssertEqual(HCaptchaError.sessionTimeout, error as? HCaptchaError) exp1.fulfill() case .open: exp3.fulfill() diff --git a/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift b/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift index a1a4b94..0b73451 100644 --- a/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift +++ b/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift @@ -21,7 +21,7 @@ extension HCaptchaWebViewManager { messageBody: String = "undefined", apiKey: String? = nil, endpoint: URL? = nil, - shouldFail: Bool = false, + shouldFail: Bool = false, // will fail with retriable sessionTimeout size: HCaptchaSize = .invisible, rqdata: String? = nil, theme: String = "\"light\"", diff --git a/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift b/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift index 05d09e1..48bd237 100644 --- a/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift +++ b/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift @@ -231,7 +231,7 @@ class HCaptcha_Rx__Tests: XCTestCase { .single() } catch let error { - XCTAssertEqual(error as? HCaptchaError, .wrongMessageFormat) + XCTAssertEqual(error as? HCaptchaError, .sessionTimeout) // Resets after failure _ = Observable.just(()) diff --git a/Example/HCaptcha_Tests/mock.html b/Example/HCaptcha_Tests/mock.html index c951faa..e6ff52f 100644 --- a/Example/HCaptcha_Tests/mock.html +++ b/Example/HCaptcha_Tests/mock.html @@ -29,7 +29,7 @@ var execute = function() { if (shouldFail) { - post("error"); + post({error: 15}); // .sessionTimeout } else { if (rqdata) { post({"log": rqdata}); diff --git a/HCaptcha/Classes/HCaptchaWebViewManager.swift b/HCaptcha/Classes/HCaptchaWebViewManager.swift index aa51c37..df8811a 100644 --- a/HCaptcha/Classes/HCaptchaWebViewManager.swift +++ b/HCaptcha/Classes/HCaptchaWebViewManager.swift @@ -258,21 +258,19 @@ fileprivate extension HCaptchaWebViewManager { } private func handle(error: HCaptchaError) { - switch error { - case HCaptchaError.challengeClosed: completion?(HCaptchaResult(self, error: error)) - case HCaptchaError.networkError: - if let completion = completion { - completion(HCaptchaResult(self, error: error)) - } else { - lastError = error - } - default: + if error == .sessionTimeout { if shouldResetOnError, let view = webView.superview { reset() validate(on: view) } else { completion?(HCaptchaResult(self, error: error)) } + } else { + if let completion = completion { + completion(HCaptchaResult(self, error: error)) + } else { + lastError = error + } } }