Skip to content

Commit fa6ab36

Browse files
committed
minor: Remove error from AppStateContext
1 parent dfee2f5 commit fa6ab36

5 files changed

Lines changed: 22 additions & 37 deletions

File tree

src/state/context.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use super::*;
1212
/// by rendering the AppStateError into an axum Response.
1313
pub struct AppStateContext {
1414
pub db: DatabaseOperator,
15-
pub errors: Vec<AppStateError>,
1615
pub free_space: FreeSpace,
1716
pub state: AppState,
1817
pub user: Option<User>,
@@ -29,7 +28,6 @@ impl FromRequestParts<AppState> for AppStateContext {
2928

3029
Ok(Self {
3130
db: DatabaseOperator::new(state.clone(), user.clone()),
32-
errors: vec![],
3331
free_space: state.free_space()?,
3432
state: state.clone(),
3533
user,

src/state/error.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,21 @@ impl AppStateError {
6161
/// Global error page generated from an [AppStateError].
6262
#[derive(Debug, Template, WebTemplate)]
6363
#[template(path = "error.html")]
64-
pub struct AppStateErrorContext {
65-
state: AppStateErrorContextInner,
66-
}
67-
68-
/// Helper struct so we can reuse base.html
69-
/// with all it's `state.foo` expressions.
70-
#[derive(Debug)]
71-
pub struct AppStateErrorContextInner {
72-
// TODO: askama doesn't handle recursion well, so we convert
73-
// all errors to strings. Maybe related to:
74-
// https://github.com/askama-rs/askama/issues/393
64+
pub struct AppStateErrorTemplate {
7565
errors: Vec<AppStateError>,
7666
}
7767

78-
impl From<AppStateError> for AppStateErrorContext {
68+
impl From<AppStateError> for AppStateErrorTemplate {
7969
fn from(e: AppStateError) -> Self {
8070
// An error is being displayed to the user, make sure it's also written in the logs
8171
e.log();
82-
Self {
83-
state: AppStateErrorContextInner { errors: vec![e] },
84-
}
72+
Self { errors: vec![e] }
8573
}
8674
}
8775

8876
impl IntoResponse for AppStateError {
8977
fn into_response(self) -> Response {
90-
let error_context = AppStateErrorContext::from(self);
78+
let error_context = AppStateErrorTemplate::from(self);
9179
(StatusCode::INTERNAL_SERVER_ERROR, error_context).into_response()
9280
}
9381
}

templates/base.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,7 @@
1515
{% include "menus/header.html" %}
1616

1717
<section class="section" style="padding-top: 100px;">
18-
<div class="container">
19-
{% for error in state.errors %}
20-
<div class="notification is-danger">
21-
<details>
22-
<summary>{{ error }}</summary>
23-
<ul class="ml-5">
24-
{% for inner_error in error.inner_errors() %}
25-
<li>→ {{ inner_error }}</li>
26-
{% endfor %}
27-
</ul>
28-
</details>
29-
</div>
30-
{% endfor %}
31-
</div>
32-
18+
{% block errors %}{% endblock %}
3319
{% block main %}{% endblock %}
3420
</section>
3521

templates/error.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
{% extends "base.html" %}
22

3-
{% block main %}
3+
{% block errors %}
4+
<div class="container">
5+
{% for error in errors %}
6+
<div class="notification is-danger">
7+
<details>
8+
<summary>{{ error }}</summary>
9+
<ul class="ml-5">
10+
{% for inner_error in error.inner_errors() %}
11+
<li>→ {{ inner_error }}</li>
12+
{% endfor %}
13+
</ul>
14+
</details>
15+
</div>
16+
{% endfor %}
17+
</div>
418
{% endblock %}
519

620
{% block footer_extra %}
21+
{# Maybe we failed to load some of the global state displayed in the footer #}
722
{% endblock %}

templates/progress.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ <h1>Torrents list</h1>
2020

2121
<div class="card mt-4">
2222
<div class="card-body">
23-
{% if state.errors.len() != 0 %}
24-
<h2>Could not reach Bittorrent client (see errors above)</h2>
25-
{% else if torrent_list.torrents.len() == 0 %}
23+
{% if torrent_list.torrents.len() == 0 %}
2624
{% include "shared/empty_state.html" %}
2725
{% else %}
2826
{% include "progress_table.html" %}

0 commit comments

Comments
 (0)