mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Add HTTP error handling to CLI example
This commit is contained in:
parent
dba526bb3e
commit
a3c7dc494b
4 changed files with 17 additions and 17 deletions
|
@ -45,16 +45,16 @@ pub fn roc_fx_putLine(line: RocStr) -> () {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn roc_fx_httpGetUtf8(url: RocStr) -> RocStr {
|
||||
let body = ureq::get(unsafe { url.as_str() })
|
||||
.call()
|
||||
.unwrap_or_else(|err| todo!("Report this HTTP error: {:?}", err));
|
||||
|
||||
let str = body
|
||||
.into_string()
|
||||
.unwrap_or_else(|err| todo!("Report this body.text() error: {:?}", err));
|
||||
|
||||
RocStr::from_slice(str.as_bytes())
|
||||
pub fn roc_fx_httpGetUtf8(url: RocStr) -> RocResult<RocStr, RocStr> {
|
||||
match ureq::get(unsafe { url.as_str() }).call() {
|
||||
Ok(resp) => match resp.into_string() {
|
||||
Ok(contents) => RocResult::Ok(RocStr::from_slice(contents.as_bytes())), // TODO make roc::Result!
|
||||
// TODO turn this error into an enum!
|
||||
Err(err) => RocResult::Err(RocStr::from_slice(format!("{:?}", err).as_bytes())),
|
||||
},
|
||||
// TODO turn this error into an enum!
|
||||
Err(err) => RocResult::Err(RocStr::from_slice(format!("{:?}", err).as_bytes())),
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue