@@ -20,7 +20,7 @@ public static void ConfigureEndpoints(this WebApplication app)
2020
2121 group . MapGet ( "/longestdownwardtrend" ,
2222 async Task < Results < Ok < LongestDownwardTrendResponse > , NoContent ,
23- BadRequest , StatusCodeHttpResult , ProblemHttpResult > >
23+ BadRequest , StatusCodeHttpResult , UnauthorizedHttpResult , ProblemHttpResult > >
2424 ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
2525 {
2626 try
@@ -38,18 +38,23 @@ public static void ConfigureEndpoints(this WebApplication app)
3838 {
3939 return TypedResults . StatusCode ( ( int ) HttpStatusCode . TooManyRequests ) ;
4040 }
41+ catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . Unauthorized )
42+ {
43+ return TypedResults . Problem ( detail : "Query spanning over 365 days" , statusCode : ( int ) HttpStatusCode . Unauthorized ) ;
44+ }
4145 catch ( HttpRequestException )
4246 {
4347 return TypedResults . Problem ( statusCode : ( int ) HttpStatusCode . InternalServerError ) ;
4448 }
4549 } )
4650 . WithDescription ( "Get longest downward trend in days between given dates" )
4751 . ProducesProblem ( ( int ) HttpStatusCode . TooManyRequests )
52+ . ProducesProblem ( ( int ) HttpStatusCode . Unauthorized )
4853 . ProducesProblem ( ( int ) HttpStatusCode . InternalServerError ) ;
4954
5055 group . MapGet ( "/highestradingvolume" ,
5156 async Task < Results < Ok < HighestTradingVolumeResponse > , NoContent ,
52- BadRequest , StatusCodeHttpResult , ProblemHttpResult > >
57+ BadRequest , StatusCodeHttpResult , UnauthorizedHttpResult , ProblemHttpResult > >
5358 ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
5459 {
5560 try
@@ -69,18 +74,23 @@ public static void ConfigureEndpoints(this WebApplication app)
6974 {
7075 return TypedResults . StatusCode ( ( int ) HttpStatusCode . TooManyRequests ) ;
7176 }
77+ catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . Unauthorized )
78+ {
79+ return TypedResults . Problem ( detail : "Query spanning over 365 days" , statusCode : ( int ) HttpStatusCode . Unauthorized ) ;
80+ }
7281 catch ( HttpRequestException )
7382 {
7483 return TypedResults . Problem ( statusCode : ( int ) HttpStatusCode . InternalServerError ) ;
7584 }
7685 } )
7786 . WithDescription ( "Get the date with the highest trading volume between given dates" )
7887 . ProducesProblem ( ( int ) HttpStatusCode . TooManyRequests )
88+ . ProducesProblem ( ( int ) HttpStatusCode . Unauthorized )
7989 . ProducesProblem ( ( int ) HttpStatusCode . InternalServerError ) ;
8090
8191 group . MapGet ( "/buyandsell" ,
8292 async Task < Results < Ok < BuyAndSellResponse > , NoContent ,
83- BadRequest , StatusCodeHttpResult , ProblemHttpResult > >
93+ BadRequest , StatusCodeHttpResult , UnauthorizedHttpResult , ProblemHttpResult > >
8494 ( IMarketService service , DateOnly fromDate , DateOnly toDate ) =>
8595 {
8696 try
@@ -100,13 +110,18 @@ public static void ConfigureEndpoints(this WebApplication app)
100110 {
101111 return TypedResults . StatusCode ( ( int ) HttpStatusCode . TooManyRequests ) ;
102112 }
113+ catch ( HttpRequestException ex ) when ( ex . StatusCode == HttpStatusCode . Unauthorized )
114+ {
115+ return TypedResults . Problem ( detail : "Query spanning over 365 days" , statusCode : ( int ) HttpStatusCode . Unauthorized ) ;
116+ }
103117 catch ( HttpRequestException )
104118 {
105119 return TypedResults . Problem ( statusCode : ( int ) HttpStatusCode . InternalServerError ) ;
106120 }
107121 } )
108122 . WithDescription ( "Get pair of dates when it is best to buy and sell between given dates" )
109123 . ProducesProblem ( ( int ) HttpStatusCode . TooManyRequests )
124+ . ProducesProblem ( ( int ) HttpStatusCode . Unauthorized )
110125 . ProducesProblem ( ( int ) HttpStatusCode . InternalServerError ) ;
111126 }
112127}
0 commit comments