@@ -26,33 +26,11 @@ public GetConsoleLogsResource(IConsoleLogsService consoleLogsService)
2626 /// <returns>A JObject containing the list of logs with pagination info</returns>
2727 public override JObject Fetch ( JObject parameters )
2828 {
29- string logType = null ;
30- int offset = 0 ;
31- int limit = 100 ;
29+ string logType = parameters ? [ "logType" ] ? . ToString ( ) ;
30+ if ( string . IsNullOrWhiteSpace ( logType ) ) logType = null ;
3231
33- if ( parameters != null )
34- {
35- // Extract logType
36- if ( parameters . ContainsKey ( "logType" ) && parameters [ "logType" ] != null )
37- {
38- logType = parameters [ "logType" ] . ToString ( ) ? . ToLowerInvariant ( ) ;
39- if ( string . IsNullOrWhiteSpace ( logType ) )
40- {
41- logType = null ;
42- }
43- }
44-
45- // Extract pagination parameters
46- if ( parameters . ContainsKey ( "offset" ) && parameters [ "offset" ] != null )
47- {
48- int . TryParse ( parameters [ "offset" ] . ToString ( ) , out offset ) ;
49- }
50-
51- if ( parameters . ContainsKey ( "limit" ) && parameters [ "limit" ] != null )
52- {
53- int . TryParse ( parameters [ "limit" ] . ToString ( ) , out limit ) ;
54- }
55- }
32+ int offset = Math . Max ( 0 , GetIntParameter ( parameters , "offset" , 0 ) ) ;
33+ int limit = Math . Max ( 1 , Math . Min ( 1000 , GetIntParameter ( parameters , "limit" , 100 ) ) ) ;
5634
5735 // Use the new paginated method
5836 JObject result = _consoleLogsService . GetLogsAsJson ( logType , offset , limit ) ;
@@ -62,11 +40,27 @@ public override JObject Fetch(JObject parameters)
6240
6341 var pagination = result [ "pagination" ] as JObject ;
6442 string typeFilter = logType != null ? $ " of type '{ logType } '" : "" ;
65- result [ "message" ] = $ "Retrieved { pagination [ "returnedCount" ] } of { pagination [ "filteredCount" ] } log entries{ typeFilter } (offset: { offset } , limit: { limit } )";
43+ int returnedCount = pagination ? [ "returnedCount" ] ? . Value < int > ( ) ?? 0 ;
44+ int filteredCount = pagination ? [ "filteredCount" ] ? . Value < int > ( ) ?? 0 ;
45+ result [ "message" ] = $ "Retrieved { returnedCount } of { filteredCount } log entries{ typeFilter } (offset: { offset } , limit: { limit } )";
6646
6747 return result ;
6848 }
6949
50+ /// <summary>
51+ /// Helper method to safely extract integer parameters with default values
52+ /// </summary>
53+ /// <param name="parameters">JObject containing parameters</param>
54+ /// <param name="key">Parameter key to extract</param>
55+ /// <param name="defaultValue">Default value if parameter is missing or invalid</param>
56+ /// <returns>Extracted integer value or default</returns>
57+ private static int GetIntParameter ( JObject parameters , string key , int defaultValue )
58+ {
59+ if ( parameters ? [ key ] != null && int . TryParse ( parameters [ key ] . ToString ( ) , out int value ) )
60+ return value ;
61+ return defaultValue ;
62+ }
63+
7064
7165 }
7266}
0 commit comments