Skip to content

Commit

Permalink
docs(api): [#143] move comment
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jan 13, 2023
1 parent 0940463 commit 6ddbdd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 20 additions & 0 deletions src/apis/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ use crate::apis::resources::torrent::{ListItem, Torrent};
use crate::tracker::services::statistics::TrackerMetrics;
use crate::tracker::services::torrent::{BasicInfo, Info};

/* code-review:
When Axum cannot parse a path or query param it shows a message like this:
For the "seconds_valid_or_key" path param:
"Invalid URL: Cannot parse "-1" to a `u64`"
That message is not an informative message, specially if you have more than one param.
We should show a message similar to the one we use when we parse the value in the handler.
For example:
"Invalid URL: invalid infohash param: string \"INVALID VALUE\", expected a 40 character long string"
We can customize the error message by using a custom type with custom serde deserialization.
The same we are using for the "InfoHashVisitor".
Input data from HTTP requests should use struts with primitive types (first level of validation).
We can put the second level of validation in the application and domain services.
*/

#[derive(Serialize, Debug)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum ActionStatus<'a> {
Expand Down
20 changes: 0 additions & 20 deletions src/apis/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@ use super::handlers::{
use super::middlewares::auth::auth;
use crate::tracker::Tracker;

/* code-review:
When Axum cannot parse a path or query param it shows a message like this:
For the "seconds_valid_or_key" path param:
"Invalid URL: Cannot parse "-1" to a `u64`"
That message is not an informative message, specially if you have more than one param.
We should show a message similar to the one we use when we parse the value in the handler.
For example:
"Invalid URL: invalid infohash param: string \"INVALID VALUE\", expected a 40 character long string"
We can customize the error message by using a custom type with custom serde deserialization.
The same we are using for the "InfoHashVisitor".
Input data from HTTP requests should use struts with primitive types (first level of validation).
We can put the second level of validation in the application and domain services.
*/

pub fn router(tracker: &Arc<Tracker>) -> Router {
Router::new()
// Stats
Expand Down

0 comments on commit 6ddbdd9

Please sign in to comment.