fix: code review notes
This commit is contained in:
parent
47217f7a59
commit
3bab367ce2
|
|
@ -59,4 +59,13 @@ public struct WebViewJSError: WebViewError, Codable {
|
|||
self.columnNumber = columnNumber
|
||||
self.stackTrace = stackTrace
|
||||
}
|
||||
|
||||
public init?(from json: [String: Any]) {
|
||||
guard let data = try? JSONSerialization.data(withJSONObject: json),
|
||||
let error = try? JSONDecoder().decode(WebViewJSError.self, from: data) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self = error
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ open class BaseInitializableWebView: WKWebView,
|
|||
|
||||
// MARK: - Public methods
|
||||
|
||||
public func subscribe(onProgress: ParameterClosure<Double>? = nil) -> NSKeyValueObservation {
|
||||
public func subscribe(onProgress: ParameterClosure<Double>?) -> NSKeyValueObservation {
|
||||
observe(\.estimatedProgress, options: [.new]) { webView, change in
|
||||
if webView.isLoading, let newValue = change.newValue {
|
||||
onProgress?(newValue)
|
||||
|
|
|
|||
|
|
@ -46,21 +46,18 @@ open class DefaultWebViewModel: NSObject, WebViewModel {
|
|||
open func userContentController(_ userContentController: WKUserContentController,
|
||||
didReceive message: WKScriptMessage) {
|
||||
|
||||
if message.name == WebViewErrorConstants.errorMessageName {
|
||||
let error = parseError(message)
|
||||
if message.name == WebViewErrorConstants.errorMessageName,
|
||||
let error = parseError(message) {
|
||||
errorHandler.didRecievedError(error)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private methods
|
||||
|
||||
private func parseError(_ message: WKScriptMessage) -> WebViewError {
|
||||
let body = message.body as? [String: Any]
|
||||
return WebViewJSError(sourceURL: body?[WebViewErrorConstants.errorUrl] as? String,
|
||||
name: body?[WebViewErrorConstants.errorName] as? String,
|
||||
message: body?[WebViewErrorConstants.errorMessage] as? String,
|
||||
lineNumber: body?[WebViewErrorConstants.errorLineNumber] as? Int,
|
||||
columnNumber: body?[WebViewErrorConstants.errorColumnNumber] as? Int,
|
||||
stackTrace: body?[WebViewErrorConstants.errorStack] as? String)
|
||||
private func parseError(_ message: WKScriptMessage) -> WebViewError? {
|
||||
guard let body = message.body as? [String: Any] else {
|
||||
return nil
|
||||
}
|
||||
return WebViewJSError(from: body)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue