Conversation
Check JSON response bodies for non-zero ret or errcode values on send, typing, and lifecycle notification endpoints. Map session expiration responses to the existing SessionExpired error so callers can apply the same cooldown behavior as polling. Co-Authored-By: Anda Bot <noreply@anda.bot>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds centralized parsing of iLink API error codes from JSON responses and enforces API-level success checks for several endpoints.
Changes:
- Introduced
api_error_from_json/ensure_api_successhelpers to interpretret/errcodeand map session-expired responses. - Updated
send_message,send_typing,notify_start, andnotify_stopto validate the JSON body indicates success. - Added unit tests covering success, generic API errors, and session-expired mapping.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+52
to
+57
| let errmsg = value | ||
| .get("errmsg") | ||
| .or_else(|| value.get("message")) | ||
| .or_else(|| value.get("msg")) | ||
| .and_then(serde_json::Value::as_str) | ||
| .map_or_else(|| value.to_string(), ToOwned::to_owned); |
Comment on lines
294
to
320
| /// Notify server that this bot is starting (best-effort). | ||
| pub async fn notify_start(&self) -> Result<()> { | ||
| let body = serde_json::json!({ "base_info": self.base_info() }); | ||
| let _: serde_json::Value = self | ||
| let value: serde_json::Value = self | ||
| .post_json( | ||
| "ilink/bot/msg/notifystart", | ||
| &body, | ||
| Some(Duration::from_secs(10)), | ||
| ) | ||
| .await?; | ||
| ensure_api_success(&value)?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Notify server that this bot is stopping (best-effort). | ||
| pub async fn notify_stop(&self) -> Result<()> { | ||
| let body = serde_json::json!({ "base_info": self.base_info() }); | ||
| let _: serde_json::Value = self | ||
| let value: serde_json::Value = self | ||
| .post_json( | ||
| "ilink/bot/msg/notifystop", | ||
| &body, | ||
| Some(Duration::from_secs(10)), | ||
| ) | ||
| .await?; | ||
| ensure_api_success(&value)?; | ||
| Ok(()) | ||
| } |
Comment on lines
+385
to
+386
| #[test] | ||
| fn api_status_accepts_success_body() { |
Comment on lines
+392
to
+393
| #[test] | ||
| fn api_status_rejects_nonzero_body() { |
Comment on lines
+406
to
+407
| #[test] | ||
| fn api_status_maps_session_expired_body() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
retorerrcodevalues on send, typing, and lifecycle notification endpointsSessionExpirederrorTests
cargo fmt --checkcargo testcargo clippy --all-targets -- -D warningsgit diff --check