Skip to content

Commit c382cd5

Browse files
fix(api): sanitize database constraint errors before sending to clients
Closes #914 Previously DbError::ConstraintViolation passed the raw sqlx error message (e.g. "duplicate key value violates unique constraint newsletter_subscribers_email_key") directly into the 409 response body, leaking table and column names to API consumers. Now the full constraint message is logged internally at ERROR level (where it remains visible to operators via the tracing correlation ID) and replaced with a generic client-safe message in the response body. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 86cb874 commit c382cd5

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

services/api/src/handlers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ fn into_api_error(err: anyhow::Error) -> ApiError {
9292
return ApiError::service_unavailable("database connection pool exhausted");
9393
}
9494
DbError::ConstraintViolation(msg) => {
95-
return ApiError::conflict(msg.clone());
95+
tracing::error!(db_constraint = %msg, "database constraint violation");
96+
return ApiError::conflict("A record with this value already exists.");
9697
}
9798
DbError::Other(_) => {}
9899
}

0 commit comments

Comments
 (0)