Skip to content

Extracting out &str from mongodb::error::ErrorKind::Custom() #1262

Closed
@sumit-modak

Description

@sumit-modak

This is a feature request.

    if let Err(e) = crate::database::check_and_add_user(state.as_ref(), &user).await {
        // `e` is of type mongodb::error::Error
        match e.kind.as_ref() {
            mongodb::error::ErrorKind::Custom(s) => {
                // `s` is of type &Arc<dyn Any + Send + Sync>
                return Err((
                    StatusCode::BAD_REQUEST,
                    // implement here
                    // <-- how to convert s to &str or String
                ));
            }
            _ => {
                return Err((
                    StatusCode::INTERNAL_SERVER_ERROR,
                    format!("Failed to create user"),
                ))
            }
        };
    }
    ```

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions