adding initial 404 handling

This commit is contained in:
zapsh 2023-12-03 17:07:25 -05:00
parent a187d141bd
commit 91d0de75ab
No known key found for this signature in database
GPG key ID: E5401FA0D64F5DC8
2 changed files with 25 additions and 0 deletions

View file

@ -240,6 +240,7 @@ pub enum Problem {
InvalidUrl(UrlProblem),
/// The Content-Length header of the response exceeded max_download_bytes
DownloadTooBig(u64),
NotFound,
}
pub fn download_and_hash(
@ -255,6 +256,10 @@ pub fn download_and_hash(
.send()
.map_err(Problem::HttpErr)?;
if resp.status() == reqwest::StatusCode::NOT_FOUND {
return Err(Problem::NotFound);
}
// Some servers don't return Content-Length - e.g. Netlify seems to only sometimes return it.
// If they do, and if it says the file is going to be too big, don't bother downloading it!
if let Some(content_len) = resp.content_length() {

View file

@ -1230,6 +1230,26 @@ pub fn to_https_problem_report<'b>(
severity: Severity::Fatal,
}
}
Problem::NotFound => {
let doc = alloc.stack([
alloc.reflow(r"I was trying to download this URL:"),
alloc
.string((&url).to_string())
.annotate(Annotation::Url)
.indent(4),
alloc.concat([alloc.reflow(r"But the file was not found on the server")]),
alloc.concat([
alloc.tip(),
alloc.reflow(r"Perhaps you can check that this URL is correct?"),
]),
]);
Report {
filename: "UNKNOWN.roc".into(),
doc,
title: "NOTFOUND".to_string(),
severity: Severity::Fatal,
}
}
// TODO: The reporting text for IoErr and FsExtraErr could probably be unified
Problem::IoErr(io_error) => {
let doc = alloc.stack([