Skip to content

Commit 8057469

Browse files
Update crates/trusted-server-core/src/error.rs
Co-authored-by: Aram Grigoryan <132480+aram356@users.noreply.github.com>
1 parent c65c2a0 commit 8057469

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

crates/trusted-server-core/src/error.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,45 @@ mod tests {
257257
),
258258
];
259259

260+
// `mapped_status` is an exhaustive match with no `_` arm, so adding a
261+
// new `TrustedServerError` variant fails to compile here until its
262+
// status is declared — the per-variant coverage can't silently go
263+
// stale. Cross-checking it against the independent `cases` literals
264+
// above guards both encodings against drift.
265+
fn mapped_status(error: &TrustedServerError) -> StatusCode {
266+
match error {
267+
TrustedServerError::BadRequest { .. } => StatusCode::BAD_REQUEST,
268+
TrustedServerError::Configuration { .. } | TrustedServerError::Settings { .. } => {
269+
StatusCode::INTERNAL_SERVER_ERROR
270+
}
271+
TrustedServerError::Auction { .. } => StatusCode::BAD_GATEWAY,
272+
TrustedServerError::Gam { .. } => StatusCode::BAD_GATEWAY,
273+
TrustedServerError::GdprConsent { .. } => StatusCode::BAD_REQUEST,
274+
TrustedServerError::InvalidUtf8 { .. } => StatusCode::INTERNAL_SERVER_ERROR,
275+
TrustedServerError::InvalidHeaderValue { .. } => StatusCode::BAD_REQUEST,
276+
TrustedServerError::KvStore { .. } => StatusCode::SERVICE_UNAVAILABLE,
277+
TrustedServerError::Prebid { .. } => StatusCode::BAD_GATEWAY,
278+
TrustedServerError::Integration { .. } => StatusCode::BAD_GATEWAY,
279+
TrustedServerError::Proxy { .. } => StatusCode::BAD_GATEWAY,
280+
TrustedServerError::Forbidden { .. } => StatusCode::FORBIDDEN,
281+
TrustedServerError::AllowlistViolation { .. } => StatusCode::FORBIDDEN,
282+
TrustedServerError::EdgeCookie { .. } => StatusCode::INTERNAL_SERVER_ERROR,
283+
TrustedServerError::PartnerNotFound { .. } => StatusCode::NOT_FOUND,
284+
TrustedServerError::InsecureDefault { .. } => StatusCode::INTERNAL_SERVER_ERROR,
285+
}
286+
}
287+
260288
for (error, expected_status) in cases {
261289
assert_eq!(
262290
error.status_code(),
263291
expected_status,
264292
"should map {error:?} to {expected_status}",
265293
);
294+
assert_eq!(
295+
mapped_status(&error),
296+
expected_status,
297+
"exhaustive mapping should agree with the table for {error:?}",
298+
);
266299
}
267300
}
268301

0 commit comments

Comments
 (0)