#mismatched types expected '&str', found struct 'stdstringString'
14 messages · Page 1 of 1 (latest)
but it would be much better to return an actual error type
you could do Cow<'static str> if you want to support both
It would force me to return "some string".to_owned() on others errors, while is not really great ?
could use Cow
but this error is pretty sub optimal
designing an error type would be faster, easier and far less error prone
how could I do that ? I use Validator to validate my input, and customs errors for the rest
what is Validate's error type? is it something from a crate you're using?
at its simplest, you can just wrap it.
for example: rust struct MyError{ BadRequest(ValidationError), InternalError(Box<dyn Error>), }
and then you could write (assuming you write some minor boilerplate like implementing Error and some From conversions: ```rust
#[axum_macros::debug_handler]
pub async fn update_task(
Path(id): Path<i32>,
Extension(database_conn): Extension<DatabaseConnection>,
Json(request): Json<TaskRequest>,
) -> Result<Json<TaskRequest>, MyError> {
request.validate()?;
let task: Option<tasks::Model> = tasks::Entity::find_by_id(id)
.one(&database_conn)
.await
.map_err(MyError::InternalError)?;```