mirror of
https://codeberg.org/demostf/api-client.git
synced 2026-06-03 08:34:15 +02:00
better error for setting url of unknown demo
This commit is contained in:
parent
1cefcf2f1d
commit
808c2ec0ed
2 changed files with 27 additions and 3 deletions
|
|
@ -287,7 +287,8 @@ impl ApiClient {
|
||||||
hash: [u8; 16],
|
hash: [u8; 16],
|
||||||
key: &str,
|
key: &str,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.client
|
let response = self
|
||||||
|
.client
|
||||||
.post(self.url(format!("/demos/{}/url", demo_id))?)
|
.post(self.url(format!("/demos/{}/url", demo_id))?)
|
||||||
.form(&[
|
.form(&[
|
||||||
("hash", hex::encode(hash).as_str()),
|
("hash", hex::encode(hash).as_str()),
|
||||||
|
|
@ -297,8 +298,13 @@ impl ApiClient {
|
||||||
("key", key),
|
("key", key),
|
||||||
])
|
])
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?;
|
||||||
.error_for_status()?;
|
|
||||||
|
if response.status() == StatusCode::NOT_FOUND {
|
||||||
|
return Err(Error::DemoNotFound(demo_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
response.error_for_status()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -223,6 +223,24 @@ async fn test_set_url_invalid_hash() {
|
||||||
assert!(matches!(res.unwrap_err(), Error::HashMisMatch));
|
assert!(matches!(res.unwrap_err(), Error::HashMisMatch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_set_url_unknown_demo() {
|
||||||
|
let client = test_client().await;
|
||||||
|
|
||||||
|
let res = client
|
||||||
|
.set_url(
|
||||||
|
99,
|
||||||
|
"tests",
|
||||||
|
"tests",
|
||||||
|
"http://example.com/tests",
|
||||||
|
[0; 16],
|
||||||
|
"edit",
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
dbg!(&res);
|
||||||
|
assert!(matches!(res.unwrap_err(), Error::DemoNotFound(99)));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_set_url() {
|
async fn test_set_url() {
|
||||||
let client = test_client().await;
|
let client = test_client().await;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue