|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'web_resource_error_type.dart'; |
| 6 | + |
| 7 | +/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. |
| 8 | +class WebResourceError { |
| 9 | + /// Creates a new [WebResourceError] |
| 10 | + /// |
| 11 | + /// A user should not need to instantiate this class, but will receive one in |
| 12 | + /// [WebResourceErrorCallback]. |
| 13 | + WebResourceError({ |
| 14 | + required this.errorCode, |
| 15 | + required this.description, |
| 16 | + this.domain, |
| 17 | + this.errorType, |
| 18 | + this.failingUrl, |
| 19 | + }) : assert(errorCode != null), |
| 20 | + assert(description != null); |
| 21 | + |
| 22 | + /// Raw code of the error from the respective platform. |
| 23 | + /// |
| 24 | + /// On Android, the error code will be a constant from a |
| 25 | + /// [WebViewClient](https://developer.android.com/reference/android/webkit/WebViewClient#summary) and |
| 26 | + /// will have a corresponding [errorType]. |
| 27 | + /// |
| 28 | + /// On iOS, the error code will be a constant from `NSError.code` in |
| 29 | + /// Objective-C. See |
| 30 | + /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html |
| 31 | + /// for more information on error handling on iOS. Some possible error codes |
| 32 | + /// can be found at https://developer.apple.com/documentation/webkit/wkerrorcode?language=objc. |
| 33 | + final int errorCode; |
| 34 | + |
| 35 | + /// The domain of where to find the error code. |
| 36 | + /// |
| 37 | + /// This field is only available on iOS and represents a "domain" from where |
| 38 | + /// the [errorCode] is from. This value is taken directly from an `NSError` |
| 39 | + /// in Objective-C. See |
| 40 | + /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html |
| 41 | + /// for more information on error handling on iOS. |
| 42 | + final String? domain; |
| 43 | + |
| 44 | + /// Description of the error that can be used to communicate the problem to the user. |
| 45 | + final String description; |
| 46 | + |
| 47 | + /// The type this error can be categorized as. |
| 48 | + /// |
| 49 | + /// This will never be `null` on Android, but can be `null` on iOS. |
| 50 | + final WebResourceErrorType? errorType; |
| 51 | + |
| 52 | + /// Gets the URL for which the resource request was made. |
| 53 | + /// |
| 54 | + /// This value is not provided on iOS. Alternatively, you can keep track of |
| 55 | + /// the last values provided to [WebViewPlatformController.loadUrl]. |
| 56 | + final String? failingUrl; |
| 57 | +} |
0 commit comments