feat: map DownloadCacheError via dunite ErrorClass in member-download handler (BUNYIP-48) #57

Merged
nrupard merged 1 commit from feat/bunyip-48-download-errorclass into main 2026-06-03 21:27:03 +02:00
Owner

What

Adopt dunite-download's DownloadCacheError::class() -> ErrorClass (PSA-38) in the member-download handler, replacing the hand-rolled match on DownloadCacheError variants.

Correction to the premise

BUNYIP-48 was filed assuming no member-download handler existed. It does: download_asset in bunyip-api/src/handlers/download.rs is fully implemented and wired (GET /v1/applications/{slug}/downloads/{asset_name}). It hand-rolled the error classification, with a comment already noting "PSA-38 tracks moving this classification into dunite-download." So this is the original small adoption, not a new feature.

Change

  • Re-export ErrorClass from bunyip-domain's services (next to DownloadCacheError).
  • In download_asset, classify the get_or_fetch error via e.class() instead of matching variants:
    • NotFound -> 404, no upstream-failure audit (permanent missing-asset path)
    • Upstream -> 502 + DownloadFailedUpstream audit + warn log
    • Local -> 500 + DownloadFailedUpstream audit + error log
  • Drop the now-unused DownloadCacheError / ForgejoError imports.

Behaviour is unchanged - same statuses, same audit events, same per-class logging (the error's Display still names the underlying variant in logs/audit). The classification policy now lives next to the type in dunite and cannot drift across consumers.

Acceptance criteria

  • bunyip-domain re-exports ErrorClass next to DownloadCacheError.
  • The handler maps via err.class() (NotFound -> 404, Upstream -> 502, Local -> 500); no direct match on DownloadCacheError variants.
  • The error's Display is logged/audited server-side; the client response carries no internal detail.

Verification

just check-container green: fmt + clippy -D warnings + cargo test --workspace --lib (205 lib tests).

#BUNYIP-48

## What Adopt dunite-download's `DownloadCacheError::class() -> ErrorClass` (PSA-38) in the member-download handler, replacing the hand-rolled match on `DownloadCacheError` variants. ## Correction to the premise BUNYIP-48 was filed assuming no member-download handler existed. It does: `download_asset` in `bunyip-api/src/handlers/download.rs` is fully implemented and wired (`GET /v1/applications/{slug}/downloads/{asset_name}`). It hand-rolled the error classification, with a comment already noting "PSA-38 tracks moving this classification into dunite-download." So this is the original small adoption, not a new feature. ## Change - Re-export `ErrorClass` from `bunyip-domain`'s services (next to `DownloadCacheError`). - In `download_asset`, classify the `get_or_fetch` error via `e.class()` instead of matching variants: - `NotFound` -> 404, no upstream-failure audit (permanent missing-asset path) - `Upstream` -> 502 + `DownloadFailedUpstream` audit + warn log - `Local` -> 500 + `DownloadFailedUpstream` audit + error log - Drop the now-unused `DownloadCacheError` / `ForgejoError` imports. Behaviour is unchanged - same statuses, same audit events, same per-class logging (the error's `Display` still names the underlying variant in logs/audit). The classification policy now lives next to the type in dunite and cannot drift across consumers. ## Acceptance criteria - [x] `bunyip-domain` re-exports `ErrorClass` next to `DownloadCacheError`. - [x] The handler maps via `err.class()` (NotFound -> 404, Upstream -> 502, Local -> 500); no direct match on `DownloadCacheError` variants. - [x] The error's `Display` is logged/audited server-side; the client response carries no internal detail. ## Verification `just check-container` green: fmt + clippy -D warnings + `cargo test --workspace --lib` (205 lib tests). #BUNYIP-48
feat: map DownloadCacheError via dunite ErrorClass in the member-download handler (BUNYIP-48)
All checks were successful
Check / fmt / clippy / build / test (pull_request) Successful in 1m44s
Create release / Create release from merged PR (pull_request) Has been skipped
db252a7b5c
The member-download handler (`download_asset`) already existed and was wired; it hand-rolled the upstream-vs-local classification by matching `DownloadCacheError` variants, exactly the per-consumer drift PSA-38 set out to remove (dunite-oci gets `OciError::from(&BlobCacheError)` for free; the download side should not reinvent it).

Replace the variant match with dunite-download's own `DownloadCacheError::class() -> ErrorClass` (PSA-38): NotFound -> 404 (no upstream-failure audit, a permanent missing-asset path), Upstream -> 502 + audit, Local -> 500 + audit. Re-export `ErrorClass` from bunyip-domain's services so the handler matches on `crate::services::ErrorClass`, and drop the now-unused `DownloadCacheError`/`ForgejoError` imports. Behaviour is unchanged (same statuses, same audit events, same per-class logging); the classification policy now lives next to the error type in dunite and cannot drift.

just check-container green: fmt + clippy -D warnings + cargo test --workspace --lib (205 lib tests).

#BUNYIP-48

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
nrupard deleted branch feat/bunyip-48-download-errorclass 2026-06-03 21:27:03 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
psa-systems/bunyip!57
No description provided.