HTTP client error handling
This commit is contained in:
parent
3c29fda119
commit
e9ca6ccdfe
11
src/external/musicbrainz/api/mod.rs
vendored
11
src/external/musicbrainz/api/mod.rs
vendored
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use serde::{de::DeserializeOwned, Deserialize};
|
use serde::{de::DeserializeOwned, Deserialize};
|
||||||
use url::form_urlencoded;
|
use url::form_urlencoded;
|
||||||
|
|
||||||
@ -42,6 +44,15 @@ impl From<ClientError> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ClientError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
ClientError::Client(s) => write!(f, "the API client failed: {s}"),
|
||||||
|
ClientError::Status(u) => write!(f, "the API client failed with status: {u}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct MusicBrainzApi<Mbc> {
|
pub struct MusicBrainzApi<Mbc> {
|
||||||
client: Mbc,
|
client: Mbc,
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,9 @@ use crate::tui::{
|
|||||||
selection::{Delta, ListSelection},
|
selection::{Delta, ListSelection},
|
||||||
AppPublic, AppState, IAppInteractBrowse,
|
AppPublic, AppState, IAppInteractBrowse,
|
||||||
},
|
},
|
||||||
lib::IMusicHoard, MUSICHOARD_TUI_HTTP_USER_AGENT,
|
lib::IMusicHoard,
|
||||||
};
|
MUSICHOARD_TUI_HTTP_USER_AGENT,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct AppBrowse;
|
pub struct AppBrowse;
|
||||||
|
|
||||||
@ -90,8 +91,13 @@ impl<MH: IMusicHoard> IAppInteractBrowse for AppMachine<MH, AppBrowse> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_musicbrainz(self) -> Self::APP {
|
fn fetch_musicbrainz(self) -> Self::APP {
|
||||||
let client = MusicBrainzApiClient::new(MUSICHOARD_TUI_HTTP_USER_AGENT)
|
let client = match MusicBrainzApiClient::new(MUSICHOARD_TUI_HTTP_USER_AGENT) {
|
||||||
.expect("failed to create API client");
|
Ok(client) => client,
|
||||||
|
Err(err) => {
|
||||||
|
return AppMachine::error(self.inner, format!("cannot fetch: {}", err.to_string()))
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
};
|
||||||
let mut api = MusicBrainzApi::new(client);
|
let mut api = MusicBrainzApi::new(client);
|
||||||
|
|
||||||
let coll = self.inner.music_hoard.get_collection();
|
let coll = self.inner.music_hoard.get_collection();
|
||||||
|
Loading…
Reference in New Issue
Block a user