storkit: merge 448_story_send_oauth_login_link_via_chat_when_credentials_are_missing
This commit is contained in:
@@ -161,10 +161,43 @@ pub async fn refresh_access_token() -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Extract the OAuth login URL from an error message produced by the Claude Code provider.
|
||||
///
|
||||
/// The provider returns errors like:
|
||||
/// `"OAuth session expired or credentials missing. Please log in: http://localhost:3001/oauth/authorize"`
|
||||
///
|
||||
/// Returns the URL portion when the error indicates missing or expired credentials,
|
||||
/// `None` otherwise.
|
||||
pub fn extract_login_url_from_error(err: &str) -> Option<&str> {
|
||||
let marker = "Please log in: ";
|
||||
let start = err.find(marker)?;
|
||||
Some(err[start + marker.len()..].trim())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn extract_login_url_from_oauth_error() {
|
||||
let err = "OAuth session expired or credentials missing. Please log in: http://localhost:3001/oauth/authorize";
|
||||
let url = extract_login_url_from_error(err);
|
||||
assert_eq!(url, Some("http://localhost:3001/oauth/authorize"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_login_url_returns_none_for_unrelated_error() {
|
||||
let err = "Some other error occurred";
|
||||
assert!(extract_login_url_from_error(err).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_login_url_with_different_port() {
|
||||
let err = "OAuth session expired or credentials missing. Please log in: http://localhost:3002/oauth/authorize";
|
||||
let url = extract_login_url_from_error(err);
|
||||
assert_eq!(url, Some("http://localhost:3002/oauth/authorize"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_credentials_file() {
|
||||
let json = r#"{
|
||||
|
||||
Reference in New Issue
Block a user