Skip to content

Commit

Permalink
Merge branch 'master' into feature/skip-timeout-error-after-demateria…
Browse files Browse the repository at this point in the history
…lize
  • Loading branch information
CAMOBAP committed Apr 18, 2024
2 parents 8ce8926 + c585511 commit 52492ec
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down
2 changes: 1 addition & 1 deletion Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>.just(())
Expand Down
2 changes: 1 addition & 1 deletion Example/HCaptcha_Tests/mock.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

var execute = function() {
if (shouldFail) {
post("error");
post({error: 15}); // .sessionTimeout
} else {
if (rqdata) {
post({"log": rqdata});
Expand Down
16 changes: 7 additions & 9 deletions HCaptcha/Classes/HCaptchaWebViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 52492ec

Please sign in to comment.