Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub struct ApiError {
message: String,
}

impl ApiError {
pub fn status_code(&self) -> u16 {
self.status
}
}
Comment on lines +56 to +60

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description focuses on adding an optional iss claim, but this change also adds a new public API (ApiError::status_code). If this method is required for the JWT issuer work, please update the PR description to mention it; otherwise consider splitting it into a separate PR to keep changes scoped and easier to review/revert.

Copilot uses AI. Check for mistakes.

impl Display for ApiError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}: {}", self.status, self.message)
Expand Down
2 changes: 2 additions & 0 deletions src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ pub(crate) fn decode_jwt(token: &str, hmac_secret: &str) -> Result<Claims, Error
pub(crate) struct Claims {
pub prompt: String,
pub exp: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub iss: Option<String>,
}
3 changes: 3 additions & 0 deletions src/tests/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn decode_jwt_expired_token() {
let claims = Claims {
prompt: "expired prompt".to_string(),
exp: 1, // Expired long ago (Unix epoch)
iss: Some("test".to_string()),
};
let token = jsonwebtoken::encode(
&jsonwebtoken::Header::default(),
Expand All @@ -54,6 +55,7 @@ fn decode_jwt_valid_token() {
let claims = Claims {
prompt: "test prompt".to_string(),
exp: 9999999999,
iss: Some("test".to_string()),
};
let token = jsonwebtoken::encode(
&jsonwebtoken::Header::default(),
Expand Down Expand Up @@ -81,6 +83,7 @@ fn message_encrypted_variant_decrypts() {
let claims = Claims {
prompt: "encrypted prompt".to_string(),
exp: 9999999999,
iss: Some("test".to_string()),
};
let token = jsonwebtoken::encode(
&jsonwebtoken::Header::default(),
Expand Down
Loading