| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
//! Defines the error types for this module. |
| 6 |
|
| 7 |
/// The error type for all Search component operations. These errors are |
| 8 |
/// exposed to your application, which should handle them as needed. |
| 9 |
use error_support::{ErrorHandling, GetErrorHandling}; |
| 10 |
|
| 11 |
use remote_settings::RemoteSettingsError; |
| 12 |
|
| 13 |
/// A list of errors that are internal to the component. This is the error |
| 14 |
/// type for private and crate-internal methods, and is never returned to the |
| 15 |
/// application. |
| 16 |
#[derive(Debug, thiserror::Error)] |
| 17 |
pub enum Error { |
| 18 |
#[error("Search configuration not specified")] |
| 19 |
SearchConfigNotSpecified, |
| 20 |
#[error("Search configuration overrides not specified")] |
| 21 |
SearchConfigOverridesNotSpecified, |
| 22 |
#[error("No search config v2 records received from remote settings")] |
| 23 |
SearchConfigNoRecords, |
| 24 |
#[error("No search config overrides v2 records received from remote settings")] |
| 25 |
SearchConfigOverridesNoRecords, |
| 26 |
#[error("JSON error: {0}")] |
| 27 |
Json(#[from] serde_json::Error), |
| 28 |
#[error("Remote Settings error: {0}")] |
| 29 |
RemoteSettings(#[from] RemoteSettingsError), |
| 30 |
} |
| 31 |
|
| 32 |
// #[non_exhaustive] |
| 33 |
#[derive(Debug, thiserror::Error, uniffi::Error)] |
| 34 |
pub enum SearchApiError { |
| 35 |
#[error("Other error: {reason}")] |
| 36 |
Other { reason: String }, |
| 37 |
} |
| 38 |
|
| 39 |
// Define how our internal errors are handled and converted to external errors. |
| 40 |
impl GetErrorHandling for Error { |
| 41 |
type ExternalError = SearchApiError; |
| 42 |
|
| 43 |
fn get_error_handling(&self) -> ErrorHandling<Self::ExternalError> { |
| 44 |
ErrorHandling::convert(SearchApiError::Other { |
| 45 |
reason: self.to_string(), |
| 46 |
}) |
| 47 |
.report_error("search-unexpected") |
| 48 |
} |
| 49 |
} |