Refactor: Consolidate handler error boilerplate (ApiError + ChannelMember extractor) #83
Labels
No labels
area:api
area:core
area:docs
area:infra
area:ux
dependencies
documentation
duplicate
good first issue
help wanted
invalid
question
rust
status:complete
status:partial
status:planned
type:bug
type:design
type:feature
type:infra
type:refactor
type:refactor
type:research
type:ux
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
icub3d/decentcom#83
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Category: Refactor / simplification — found in code review 2026-07-07.
Problem
~11 resource modules each redefine an identical
struct ErrorBody,type ApiResult<T>, and helpersbad_request/not_found/forbidden/conflict/internal/storage_err(messages, channels, reactions, roles, invites, membership, threads, attachments, profiles, auth, plus permissions.rs and gateway/handler.rs). Each handler also repeats the same auth → permission → channel-existence prologue.Fix
crate::error::ApiErrorenum implementingIntoResponsewithFrom<StorageError>, and a crate-widepub type ApiResult<T> = Result<Json<T>, ApiError>. Handlers then use?directly.ChannelMember { perms, channel_id, user_id }extractor (FromRequestParts) that resolves the channel, verifies existence, and computeseffective_permissionsonce — mirroring the existingMemberUser/UserPermissionsextractors.Removes several hundred lines and makes error-shape + check-ordering consistent.