- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
enum ErrorViewHelper {
    static var errorIsShown = false
    static var errorView: ErrorView?
    private static var errorWindow: UIWindow = {
        let width = (UIApplication.shared.delegate as? AppDelegate)?.window?.frame.size.width ?? 300
        let window = UIWindow(frame: CGRect(x: 0, y: 0, width: width, height: 300))
        return window
    }()
    static func show(error: Error) {
        if let error = error as? RequestError {
            switch error {
            case .error(description: let text):
                showErrorView(error: text)
            case .errorWithMeta(description: let text, meta: _):
                showErrorView(error: text)
            case .needAuthError:
                showErrorAlert(title: nil, message: R.string.localizable.needAuthError()) {
                    // TODO: remove router from this class
                    AuthRouterImpl().showAuthPage()
                    AuthRouterImpl().showAuthFlowModally()
                }
            case .badResponse:
                showErrorView(error: R.string.localizable.badResponse())
            default: break
            }
        } else {
            showErrorView(error: error.text)
        }
    }