sb-core: DomainError + signature conversions (WI-2, issue #2)
This commit is contained in:
parent
093012af20
commit
423997f2d7
5 changed files with 76 additions and 38 deletions
|
|
@ -477,7 +477,8 @@ async fn run_adventure(
|
|||
}
|
||||
char.nerve -= zone.nerve_cost;
|
||||
|
||||
let enemy = domain::pick_enemy(&mut rng, &zone.encounters, &state.enemies);
|
||||
let enemy = domain::pick_enemy(&mut rng, &zone.encounters, &state.enemies)
|
||||
.map_err(|_| axum::http::StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
(char.clone(), enemy)
|
||||
};
|
||||
|
||||
|
|
@ -698,8 +699,10 @@ async fn train_stat(
|
|||
sb_core::character::apply_regen(char, now);
|
||||
|
||||
let new_val = domain::train_stat(char, &input.stat).map_err(|e| match e {
|
||||
"not enough energy" => axum::http::StatusCode::UNPROCESSABLE_ENTITY,
|
||||
"not enough gold" => axum::http::StatusCode::UNPROCESSABLE_ENTITY,
|
||||
sb_core::error::DomainError::NotEnoughEnergy
|
||||
| sb_core::error::DomainError::NotEnoughGold => {
|
||||
axum::http::StatusCode::UNPROCESSABLE_ENTITY
|
||||
}
|
||||
_ => axum::http::StatusCode::BAD_REQUEST,
|
||||
})?;
|
||||
|
||||
|
|
@ -1204,13 +1207,7 @@ async fn level_up(
|
|||
.ok_or(axum::http::StatusCode::NOT_FOUND)?;
|
||||
match character::level_up(char) {
|
||||
Ok(_) => char.clone(),
|
||||
Err(msg) => {
|
||||
let status = match msg {
|
||||
"not enough XP" => axum::http::StatusCode::UNPROCESSABLE_ENTITY,
|
||||
_ => axum::http::StatusCode::UNPROCESSABLE_ENTITY,
|
||||
};
|
||||
return Err(status);
|
||||
}
|
||||
Err(_) => return Err(axum::http::StatusCode::UNPROCESSABLE_ENTITY),
|
||||
}
|
||||
};
|
||||
persist_character(&state, &updated).await;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue