Skip to content

Commit ed89429

Browse files
committed
Improve error messages for dispatch failures
1 parent 37a77e0 commit ed89429

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crates/chat-cli/src/auth/pkce.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ use crate::auth::{
5656
AuthError,
5757
START_URL,
5858
};
59+
use crate::aws_common::SdkErrorDisplay;
60+
use aws_smithy_runtime_api::client::result::SdkError;
5961
use crate::database::Database;
6062

6163
const DEFAULT_AUTHORIZATION_TIMEOUT: Duration = Duration::from_secs(60 * 3);
@@ -139,7 +141,10 @@ impl PkceClient for Client {
139141
for scope in Self::scopes() {
140142
register = register.scopes(scope);
141143
}
142-
let output = register.send().await?;
144+
let output = register.send().await.map_err(|e| match e {
145+
SdkError::DispatchFailure(_) => AuthError::OAuthCustomError(format!("Authentication failed: {}", SdkErrorDisplay(&e))),
146+
other => other.into()
147+
})?;
143148
Ok(RegisterClientResponse { output })
144149
}
145150

@@ -153,7 +158,11 @@ impl PkceClient for Client {
153158
.code_verifier(args.code_verifier)
154159
.code(args.code)
155160
.send()
156-
.await?;
161+
.await
162+
.map_err(|e| match e {
163+
SdkError::DispatchFailure(_) => AuthError::OAuthCustomError(format!("Authentication failed: {}", SdkErrorDisplay(&e))),
164+
other => other.into()
165+
})?;
157166
Ok(CreateTokenResponse { output })
158167
}
159168
}

0 commit comments

Comments
 (0)