@@ -11,6 +11,7 @@ use num_derive::FromPrimitive;
1111use serde:: { Deserialize , Serialize } ;
1212use sqlx:: Type ;
1313use std:: str:: FromStr ;
14+ use log:: { error, warn} ;
1415use crate :: commands:: command_repo:: SaveCommandError ;
1516use crate :: state:: L1Arc ;
1617
@@ -57,8 +58,8 @@ pub async fn get_all_user_commands(
5758 let commands = match search. search . as_deref ( ) {
5859 Some ( "" ) | None => command_repo:: get_all_commands_by_auto_generated ( & state. l1 . prod_db , false ) . await ,
5960 Some ( search) => command_repo:: search_all_commands_by_is_auto_generated ( & state. l1 . prod_db , search, false ) . await ,
60- } . map_err ( |_ | {
61- // log
61+ } . map_err ( |e | {
62+ error ! ( "{:?}" , e ) ;
6263 StatusCode :: INTERNAL_SERVER_ERROR
6364 } ) ?;
6465 Ok ( Json ( commands) )
@@ -72,8 +73,8 @@ pub async fn get_all_commands(
7273 let commands = match search. search . as_deref ( ) {
7374 Some ( "" ) | None => command_repo:: get_all_commands ( & l1. prod_db ) . await ,
7475 Some ( search) => command_repo:: search_all_commands ( & l1. prod_db , search) . await ,
75- } . map_err ( |_ | {
76- // log
76+ } . map_err ( |e | {
77+ error ! ( "{:?}" , e ) ;
7778 StatusCode :: INTERNAL_SERVER_ERROR
7879 } ) ?;
7980 Ok ( Json ( commands) )
@@ -85,8 +86,8 @@ pub async fn get_by_trigger_id(
8586) -> AxResult < impl IntoResponse > {
8687 Ok ( Json ( command_repo:: get_by_id ( & l1. prod_db , trigger_id. as_ref ( ) )
8788 . await
88- . map_err ( |_ | {
89- // log
89+ . map_err ( |e | {
90+ error ! ( "{:?}" , e ) ;
9091 StatusCode :: INTERNAL_SERVER_ERROR
9192 } ) ?) )
9293}
@@ -100,8 +101,8 @@ pub async fn set_enabled(
100101 let enabled = bool:: from_str ( body. as_ref ( ) ) . map_err ( |_| StatusCode :: BAD_REQUEST ) ?;
101102 command_repo:: set_enabled ( state. l1 . as_ref ( ) , trigger_id. as_ref ( ) , enabled)
102103 . await
103- . map_err ( |_ | {
104- // log
104+ . map_err ( |e | {
105+ error ! ( "{:?}" , e ) ;
105106 StatusCode :: INTERNAL_SERVER_ERROR
106107 } ) ?
107108 . ok_or ( StatusCode :: NOT_FOUND ) ?;
@@ -116,8 +117,8 @@ pub async fn set_visible(
116117 let visible = bool:: from_str ( body. as_str ( ) ) . map_err ( |_| StatusCode :: BAD_REQUEST ) ?;
117118 command_repo:: set_visible ( & l1. prod_db , trigger_id. as_str ( ) , visible)
118119 . await
119- . map_err ( |_ | {
120- // log
120+ . map_err ( |e | {
121+ error ! ( "{:?}" , e ) ;
121122 StatusCode :: INTERNAL_SERVER_ERROR
122123 } ) ?
123124 . ok_or ( StatusCode :: NOT_FOUND ) ?;
@@ -130,12 +131,12 @@ pub async fn save(
130131) -> impl IntoResponse {
131132 match command_repo:: save ( l1. as_ref ( ) , & to_save) . await {
132133 Ok ( ( ) ) => StatusCode :: OK ,
133- Err ( SaveCommandError :: DbError ( _db_error ) ) => {
134- // log
134+ Err ( SaveCommandError :: DbError ( db_error ) ) => {
135+ error ! ( "Error saving command from panel: {:?}" , db_error ) ;
135136 StatusCode :: INTERNAL_SERVER_ERROR
136137 }
137- Err ( SaveCommandError :: RegexError ( _r ) ) => {
138- // log, but actually more return. This error needs to reach the user in the panel
138+ Err ( SaveCommandError :: RegexError ( r ) ) => {
139+ warn ! ( "User tried to save invalid regex: {:?}" , r ) ;
139140 //TODO figure out how to return this error to the user
140141 StatusCode :: BAD_REQUEST
141142 }
@@ -146,8 +147,8 @@ pub async fn delete_by_id(
146147 l1 : L1Arc ,
147148 Path ( trigger_id) : Path < String > ,
148149) -> AxResult < impl IntoResponse > {
149- command_repo:: delete_by_id ( l1. as_ref ( ) , trigger_id. as_ref ( ) ) . await . map_err ( |_ | {
150- // log
150+ command_repo:: delete_by_id ( l1. as_ref ( ) , trigger_id. as_ref ( ) ) . await . map_err ( |e | {
151+ error ! ( "Unable to execute command deletion: {:?}" , e ) ;
151152 StatusCode :: INTERNAL_SERVER_ERROR
152153 } ) ?;
153154 Ok ( ( ) )
0 commit comments