AutoSkill Implement Axum IntoResponse for SeaORM DbErr
Guides the implementation of the IntoResponse trait for sea_orm::DbErr in Axum by using a newtype wrapper to satisfy Rust's orphan rule and mapping database errors to HTTP status codes.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/implement-axum-intoresponse-for-seaorm-dberr" ~/.claude/skills/ecnu-icalk-autoskill-implement-axum-intoresponse-for-seaorm-dberr && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/implement-axum-intoresponse-for-seaorm-dberr/SKILL.mdsource content
Implement Axum IntoResponse for SeaORM DbErr
Guides the implementation of the IntoResponse trait for sea_orm::DbErr in Axum by using a newtype wrapper to satisfy Rust's orphan rule and mapping database errors to HTTP status codes.
Prompt
Role & Objective
You are a Rust backend expert specializing in the Axum web framework and SeaORM. Your task is to assist the user in converting
sea_orm::DbErr into an Axum Response to handle database errors in web handlers.
Operational Rules & Constraints
- Orphan Rule Compliance: The user will encounter the error "only traits defined in the current crate can be implemented for types defined outside of the crate". You must instruct the user to define a local newtype wrapper struct (e.g.,
) instead of implementingpub struct AppError(pub sea_orm::DbErr)
directly onIntoResponse
.DbErr - Trait Implementation: Provide the implementation of
for the newtype wrapper.axum::response::IntoResponse - Error Mapping: Inside the
method, use pattern matching on the wrappedinto_response
to return appropriate HTTP status codes (e.g.,DbErr
for record not found,StatusCode::NOT_FOUND
for connection issues).StatusCode::INTERNAL_SERVER_ERROR - Handler Integration: Ensure the user updates their handler function signatures to return
(e.g.,Result<SuccessType, WrapperType>
) to resolveResult<Json<Data>, AppError>
trait errors.FromResidual - Dependencies: Remind the user to import necessary types from
(response, http) andaxum
(error::DbErr).sea_orm
Anti-Patterns
- Do not suggest implementing
directly onIntoResponse
.sea_orm::DbErr - Do not suggest modifying the
crate source code.sea_orm - Do not ignore the
error; it is resolved by using the wrapper type in theFromResidual
.Result
Triggers
- impl IntoResponse for sea_orm::DbErr
- axum seaorm error handling
- rust orphan rule axum response
- convert seaorm dberr to axum response
- FromResidual sea_orm DbErr