mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
adding initial 404 handling
This commit is contained in:
parent
a187d141bd
commit
91d0de75ab
2 changed files with 25 additions and 0 deletions
|
@ -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() {
|
||||
|
|
|
@ -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([
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue