error handling
This commit is contained in:
parent
2544143809
commit
48476d5cf4
3 changed files with 38 additions and 9 deletions
|
@ -8,6 +8,7 @@ use rocket::{State, get};
|
|||
use pacco::pkg::{Repository, arch::Architecture};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::routes::no_such_repo_error;
|
||||
use crate::routes::ui::arch_card;
|
||||
use pacco::config::Config;
|
||||
|
||||
|
@ -18,18 +19,18 @@ pub async fn repo_arch_json(
|
|||
ctx: RequestContext,
|
||||
arch: &str,
|
||||
config: &State<Config>,
|
||||
) -> serde_json::Value {
|
||||
) -> Result<serde_json::Value, serde_json::Value> {
|
||||
let arch = Architecture::parse(arch).unwrap_or(Architecture::any);
|
||||
let repo_name = repo;
|
||||
|
||||
let repo = Repository::new(repo_name).unwrap();
|
||||
let repo = Repository::new(repo_name).ok_or_else(no_such_repo_error)?;
|
||||
let packages = repo.list_pkg_arch(arch.clone());
|
||||
|
||||
json!({
|
||||
Ok(json!({
|
||||
"repo": repo_name,
|
||||
"arch": arch.to_string(),
|
||||
"packages": packages
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
/// Repository Overview UI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue