torrust / torrust-index

This repository serves as the backend for the Torrust Index project.
https://torrust.com
GNU Affero General Public License v3.0
54 stars 19 forks source link

Improve error message for duplicated canonical info-hash #776

Open josecelano opened 4 days ago

josecelano commented 4 days ago

Parent: https://github.com/torrust/torrust-index/issues/521

When you upload a torrent, you can get an error because there is already another torrent with the same canonical info-hash. The error doesn't give you the pre-existing torrent infohash.

The error:

    #[display(fmt = "A torrent with the same canonical infohash already exists in our database.")]
    CanonicalInfoHashAlreadyExists,

should give you the info-hash, so the user can search/navigate to see the pre-existing torrent.

We can do it like we do for other error enums with the thiserror crate.

use thiserror::Error;

#[derive(Debug, Error)]
pub enum ServiceError {
    #[error("internal server error: {0}")]
    InternalServerError(String),
    // other variants...
}