From 6d62a45eec64c90ca8f9de21ba8744f01f0a1c72 Mon Sep 17 00:00:00 2001 From: Alan Klas Date: Sat, 5 Oct 2024 23:43:14 +0200 Subject: [PATCH] handle a bit more errors --- src/apis/together.rs | 12 ++++++------ src/main.rs | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/apis/together.rs b/src/apis/together.rs index 265e591..e29437e 100644 --- a/src/apis/together.rs +++ b/src/apis/together.rs @@ -1,3 +1,4 @@ +use anyhow::Result; use reqwest::Client; use serde::{Deserialize, Serialize}; use std::env; @@ -44,12 +45,7 @@ impl TogetherClient { } } - pub async fn submit_request( - &self, - prompt: ImageRequest, - ) -> Result { - // base64 image - + pub async fn submit_request(&self, prompt: ImageRequest) -> Result { let response = self .client .post("https://api.together.xyz/v1/images/generations") @@ -62,6 +58,10 @@ impl TogetherClient { .send() .await?; + if !response.status().is_success() { + return Err(anyhow::anyhow!("Status code: {}", response.status())); + } + let response = response.json::().await?; Ok(response) diff --git a/src/main.rs b/src/main.rs index 8492a85..db6b15a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,6 +181,10 @@ async fn handle_command( let res = client.submit_request(request).await; if let Err(e) = res { error!("Failed to submit request: {:?}", e); + bot.send_message(message.chat.id, format!("error: {e:?}")) + .reply_parameters(ReplyParameters::new(message.id)) + .await + .unwrap(); return Ok(lambda_http::Response::builder() .status(200) .body(String::new())