-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FXIOS-9627-[Native Error Page] Initial changes for manager support #22613
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Redux | ||
import Common | ||
|
||
final class NativeErrorPageAction: Action { | ||
let networkError: NSError? | ||
let nativePageErrorModel: ErrorPageModel? | ||
init( | ||
networkError: NSError? = nil, | ||
nativePageErrorModel: ErrorPageModel? = nil, | ||
windowUUID: WindowUUID, | ||
actionType: any ActionType | ||
) { | ||
self.networkError = networkError | ||
self.nativePageErrorModel = nativePageErrorModel | ||
super.init(windowUUID: windowUUID, actionType: actionType) | ||
} | ||
} | ||
|
||
enum NativeErrorPageActionType: ActionType { | ||
case receivedError | ||
} | ||
|
||
enum NativeErrorPageMiddlewareActionType: ActionType { | ||
case initialize | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Common | ||
import Foundation | ||
import WebKit | ||
import GCDWebServers | ||
import Shared | ||
import Storage | ||
|
||
class NativeErrorPageHelper { | ||
enum NetworkErrorType { | ||
case noInternetConnection | ||
} | ||
|
||
var error: NSError | ||
|
||
var errorDescriptionItem: String { | ||
return error.localizedDescription | ||
} | ||
|
||
init(error: NSError) { | ||
self.error = error | ||
} | ||
|
||
func parseErrorDetails() -> ErrorPageModel { | ||
var title = "" | ||
var description = "" | ||
switch error.code { | ||
case Int(CFNetworkErrors.cfurlErrorNotConnectedToInternet.rawValue): | ||
title = .NativeErrorPage.NoInternetConnection.TitleLabel | ||
description = .NativeErrorPage.NoInternetConnection.Description | ||
default: | ||
break | ||
} | ||
|
||
let model = ErrorPageModel(errorTitle: title, errorDescription: description) | ||
return model | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||||||||||||
// This Source Code Form is subject to the terms of the Mozilla Public | ||||||||||||||||||||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||||||||||||||||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import Foundation | ||||||||||||||||||||||||
import Redux | ||||||||||||||||||||||||
import Shared | ||||||||||||||||||||||||
import Common | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
final class NativeErrorPageMiddleware { | ||||||||||||||||||||||||
lazy var nativeErrorPageProvider: Middleware<AppState> = { state, action in | ||||||||||||||||||||||||
let windowUUID = action.windowUUID | ||||||||||||||||||||||||
print(action.actionType) | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for |
||||||||||||||||||||||||
switch action.actionType { | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spppaaaaaaccccceeeee :P |
||||||||||||||||||||||||
case NativeErrorPageActionType.receivedError: | ||||||||||||||||||||||||
guard let action = action as? NativeErrorPageAction, let error = action.networkError else {return} | ||||||||||||||||||||||||
self.initializeNativeErrorPage(windowUUID: windowUUID, error: error) | ||||||||||||||||||||||||
break | ||||||||||||||||||||||||
default: | ||||||||||||||||||||||||
break | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
private func initializeNativeErrorPage(windowUUID: WindowUUID, error: NSError) { | ||||||||||||||||||||||||
let model = NativeErrorPageHelper(error: error).parseErrorDetails() | ||||||||||||||||||||||||
let newAction = NativeErrorPageAction(nativePageErrorModel: model, | ||||||||||||||||||||||||
windowUUID: windowUUID, | ||||||||||||||||||||||||
actionType: NativeErrorPageMiddlewareActionType.initialize | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
store.dispatch(newAction) | ||||||||||||||||||||||||
Comment on lines
+26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit: alternative to consider that doesn't require assignment. |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Redux | ||
import Shared | ||
import Common | ||
|
||
struct NativeErrorPageState: ScreenState, Equatable { | ||
var windowUUID: WindowUUID | ||
var title: String? | ||
var description: String? | ||
|
||
init(appState: AppState, uuid: WindowUUID) { | ||
guard let nativeErrorPageState = store.state.screenState( | ||
NativeErrorPageState.self, | ||
for: .nativeErrorPage, | ||
window: uuid | ||
) else { | ||
self.init(windowUUID: uuid) | ||
return | ||
} | ||
|
||
self.init( | ||
windowUUID: nativeErrorPageState.windowUUID, | ||
title: nativeErrorPageState.title, | ||
description: nativeErrorPageState.description | ||
) | ||
} | ||
|
||
init( | ||
windowUUID: WindowUUID, | ||
title: String? = nil, | ||
description: String? = nil | ||
) { | ||
self.windowUUID = windowUUID | ||
self.title = title | ||
self.description = description | ||
} | ||
|
||
static let reducer: Reducer<Self> = { state, action in | ||
print(action.actionType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we shouldn't have these statements in production |
||
guard action.windowUUID == .unavailable || action.windowUUID == state.windowUUID else { return NativeErrorPageState( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: return can be on a separate line here |
||
windowUUID: state.windowUUID, | ||
title: state.title, | ||
description: state.description | ||
)} | ||
switch action.actionType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: leave some space so it's easier to read. Vertical space is free, we may as well take advantage! |
||
case NativeErrorPageMiddlewareActionType.initialize: | ||
guard let action = action as? NativeErrorPageAction, let model = action.nativePageErrorModel else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: spread the multiple let conditions over multiple lines for easy reading |
||
return NativeErrorPageState( | ||
windowUUID: state.windowUUID, | ||
title: state.title, | ||
description: state.description | ||
) | ||
} | ||
return NativeErrorPageState( | ||
windowUUID: state.windowUUID, | ||
title: model.errorTitle, | ||
description: model.errorDescription | ||
) | ||
default: | ||
return NativeErrorPageState( | ||
windowUUID: state.windowUUID, | ||
title: state.title, | ||
description: state.description | ||
) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space for readibility