Merge branch 'redlib-org:main' into default-filter
This commit is contained in:
commit
5193164719
@ -314,9 +314,9 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo
|
|||||||
#[cached(size = 100, time = 30, result = true)]
|
#[cached(size = 100, time = 30, result = true)]
|
||||||
pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
|
pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
|
||||||
// Closure to quickly build errors
|
// Closure to quickly build errors
|
||||||
let err = |msg: &str, e: String| -> Result<Value, String> {
|
let err = |msg: &str, e: String, path: String| -> Result<Value, String> {
|
||||||
// eprintln!("{} - {}: {}", url, msg, e);
|
// eprintln!("{} - {}: {}", url, msg, e);
|
||||||
Err(format!("{msg}: {e}"))
|
Err(format!("{msg}: {e} | {path}"))
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch the url...
|
// Fetch the url...
|
||||||
@ -339,7 +339,7 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
|
|||||||
let () = force_refresh_token().await;
|
let () = force_refresh_token().await;
|
||||||
return Err("OAuth token has expired. Please refresh the page!".to_string());
|
return Err("OAuth token has expired. Please refresh the page!".to_string());
|
||||||
}
|
}
|
||||||
Err(format!("Reddit error {} \"{}\": {}", json["error"], json["reason"], json["message"]))
|
Err(format!("Reddit error {} \"{}\": {} | {path}", json["error"], json["reason"], json["message"]))
|
||||||
} else {
|
} else {
|
||||||
Ok(json)
|
Ok(json)
|
||||||
}
|
}
|
||||||
@ -349,15 +349,15 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
|
|||||||
if status.is_server_error() {
|
if status.is_server_error() {
|
||||||
Err("Reddit is having issues, check if there's an outage".to_string())
|
Err("Reddit is having issues, check if there's an outage".to_string())
|
||||||
} else {
|
} else {
|
||||||
err("Failed to parse page JSON data", e.to_string())
|
err("Failed to parse page JSON data", e.to_string(), path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => err("Failed receiving body from Reddit", e.to_string()),
|
Err(e) => err("Failed receiving body from Reddit", e.to_string(), path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => err("Couldn't send request to Reddit", e),
|
Err(e) => err("Couldn't send request to Reddit", e, path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
use crate::config::get_setting;
|
use crate::config::get_setting;
|
||||||
//
|
//
|
||||||
// CRATES
|
// CRATES
|
||||||
@ -1028,7 +1029,7 @@ pub fn redirect(path: &str) -> Response<Body> {
|
|||||||
|
|
||||||
/// Renders a generic error landing page.
|
/// Renders a generic error landing page.
|
||||||
pub async fn error(req: Request<Body>, msg: &str) -> Result<Response<Body>, String> {
|
pub async fn error(req: Request<Body>, msg: &str) -> Result<Response<Body>, String> {
|
||||||
error!("Error page rendered: {msg}");
|
error!("Error page rendered: {}", msg.split('|').next().unwrap_or_default());
|
||||||
let url = req.uri().to_string();
|
let url = req.uri().to_string();
|
||||||
let body = ErrorTemplate {
|
let body = ErrorTemplate {
|
||||||
msg: msg.to_string(),
|
msg: msg.to_string(),
|
||||||
|
@ -2,10 +2,14 @@
|
|||||||
{% block title %}Error: {{ msg }}{% endblock %}
|
{% block title %}Error: {{ msg }}{% endblock %}
|
||||||
{% block sortstyle %}{% endblock %}
|
{% block sortstyle %}{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="error">
|
<div id="error">
|
||||||
<h1>{{ msg }}</h1>
|
<h1>{{ msg }}</h1>
|
||||||
<h3><a href="https://www.redditstatus.com/">Reddit Status</a></h3>
|
<h3><a href="https://www.redditstatus.com/">Reddit Status</a></h3>
|
||||||
<br />
|
<br />
|
||||||
<h3>Head back <a href="/">home</a>?</h3>
|
<h3>Expected something to work? <a
|
||||||
</div>
|
href="https://github.com/redlib-org/redlib/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=%F0%9F%90%9B+Bug+Report%3A+{{ msg }}">Report
|
||||||
|
an issue</a></h3>
|
||||||
|
<br />
|
||||||
|
<h3>Head back <a href="/">home</a>?</h3>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user