Skip to content

Commit

Permalink
fix: report error to user, in case of failing to save credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Jan 12, 2024
1 parent 5862b22 commit 80a81da
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/bin/sg-nvim-agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ async fn main() -> Result<()> {
let url = Url::parse(&url).expect("to parse URL");

if let Some((_, token)) = url.query_pairs().find(|(k, _)| k == "token") {
let response = tiny_http::Response::from_string(
"Credentials have been saved to Neovim. Restart Neovim now.",
);
let response = match sg::auth::set_credentials(
sg::auth::CodyCredentials {
endpoint: Some("https://sourcegraph.com/".to_string()),
token: Some(token.to_string()),
},
) {
Ok(_) => tiny_http::Response::from_string(
"Credentials have been saved to Neovim. Restart Neovim now.",
),
Err(err) => tiny_http::Response::from_string(&format!(
"Failed to save credentials - Please report this error: {}",
err
)),
};

// Ignore response errors
let _ = request.respond(response);

sg::auth::set_credentials(sg::auth::CodyCredentials {
endpoint: Some("https://sourcegraph.com/".to_string()),
token: Some(token.to_string()),
})
.expect("to set credentials");
}
});
}
Expand Down

0 comments on commit 80a81da

Please sign in to comment.