dxps / fullstack-rust-axum-dioxus-rwa

A RealWorld app implementation as a fullstack Rust project using Axum (back-end) and Dioxus (front-end).
MIT License
79 stars 6 forks source link

Better handling of article slug uniqueness #10

Closed dxps closed 1 year ago

dxps commented 1 year ago

Trying to create an article with the same slug it returns an HTTP RC 500.

And in the log it throws this:

2023-01-29T20:59:05.718215Z DEBUG backend::app_errors: From sqlx err: Database(PgDatabaseError { 
severity: Error, code: "23505", 
message: "duplicate key value violates unique constraint \"unique_slug\"", 
detail: Some("Key (slug)=(how-to-train-your-dragon) already exists."), 
hint: None, position: None, where: None, schema: Some("public"), 
table: Some("articles"), column: None, data_type: None, 
constraint: Some("unique_slug"), 
file: Some("nbtinsert.c"), line: Some(663), routine: Some("_bt_check_unique") })

It should return a 422 (Unprocessable Entity).