Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/merino/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
pub mod curated_recommendations;
pub mod suggest;
pub mod worldcup;
uniffi::setup_scaffolding!("merino");
77 changes: 77 additions & 0 deletions components/merino/src/worldcup/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* 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/. */

pub use error_support::error;
use error_support::{ErrorHandling, GetErrorHandling};

pub type Result<T> = std::result::Result<T, Error>;
pub type ApiResult<T> = std::result::Result<T, MerinoWorldCupApiError>;

#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum MerinoWorldCupApiError {
/// A network-level failure.
#[error("WorldCup network error: {reason}")]
Network { reason: String },

/// Any other error, e.g. HTTP errors, validation errors.
#[error("WorldCup error: code {code:?}, reason: {reason}")]
Other { code: Option<u16>, reason: String },
}

#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Failed to parse a URL.
#[error("URL parse error: {0}")]
UrlParse(#[from] url::ParseError),

/// Failed to send the HTTP request.
#[error("Error sending request: {0}")]
Request(#[from] viaduct::ViaductError),

/// The server rejected the request due to malformed syntax (HTTP 400).
#[error("Bad request ({code}): {message}")]
BadRequest { code: u16, message: String },

/// The server rejected the request due to invalid input (HTTP 422).
#[error("Validation error ({code}): {message}")]
Validation { code: u16, message: String },

/// The server encountered an internal error (HTTP 5xx).
#[error("Server error ({code}): {message}")]
Server { code: u16, message: String },

/// An unexpected HTTP status code was received.
#[error("Unexpected error ({code}): {message}")]
Unexpected { code: u16, message: String },
}

impl GetErrorHandling for Error {
type ExternalError = MerinoWorldCupApiError;

fn get_error_handling(&self) -> ErrorHandling<Self::ExternalError> {
match self {
Self::Request { .. } => ErrorHandling::convert(MerinoWorldCupApiError::Network {
reason: self.to_string(),
})
.log_warning(),

Self::Validation { code, .. }
| Self::Server { code, .. }
| Self::Unexpected { code, .. }
| Self::BadRequest { code, .. } => {
ErrorHandling::convert(MerinoWorldCupApiError::Other {
code: Some(*code),
reason: self.to_string(),
})
.report_error("merino-http-error")
}

Self::UrlParse(_) => ErrorHandling::convert(MerinoWorldCupApiError::Other {
code: None,
reason: self.to_string(),
})
.report_error("merino-unexpected"),
}
}
}
60 changes: 60 additions & 0 deletions components/merino/src/worldcup/fixtures/live.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"current": [
{
"date": "2026-04-30T14:00:00+00:00",
"global_event_id": 1002,
"home_team": {
"key": "ENG",
"global_team_id": 90000005,
"name": "England",
"region": "ENG",
"colors": [
"White",
"Red"
],
"icon_url": "https://storage.googleapis.com/merino-images-prod/logos/nations/nations_gb-eng.png",
"group": "Group C",
"eliminated": false,
"standing": {
"wins": 0,
"losses": 0,
"draws": 0,
"points": 0
}
},
"away_team": {
"key": "USA",
"global_team_id": 90000006,
"name": "United States",
"region": "USA",
"colors": [
"Navy",
"White",
"Red"
],
"icon_url": "https://storage.googleapis.com/merino-images-prod/logos/nations/nations_us.png",
"group": "Group C",
"eliminated": false,
"standing": {
"wins": 0,
"losses": 0,
"draws": 0,
"points": 0
}
},
"period": "2",
"home_score": 1,
"away_score": 0,
"home_extra": null,
"away_extra": null,
"home_penalty": null,
"away_penalty": null,
"clock": "67",
"updated": 1777554000,
"status": "In Progress",
"status_type": "live",
"query": null,
"sport": "soccer"
}
]
}
Loading