1
1
use axum:: extract:: State ;
2
2
use axum:: Json ;
3
- use bigdecimal:: num_bigint:: ToBigInt ;
3
+ use bigdecimal:: num_bigint:: { BigInt , ToBigInt } ;
4
4
5
5
use crate :: handlers:: entries:: GetEntryResponse ;
6
- use crate :: infra:: errors:: InfraError ;
7
6
use crate :: infra:: repositories:: entry_repository:: { self , MedianEntry } ;
8
7
use crate :: utils:: PathExtractor ;
9
8
use crate :: AppState ;
10
- use pragma_entities:: EntryError ;
9
+ use pragma_entities:: { error :: InfraError , EntryError } ;
11
10
12
11
use super :: utils:: { compute_median_price_and_time, currency_pair_to_pair_id} ;
13
12
@@ -47,6 +46,7 @@ pub async fn get_entry(
47
46
. map_err ( |db_error| match db_error {
48
47
InfraError :: InternalServerError => EntryError :: InternalServerError ,
49
48
InfraError :: NotFound => EntryError :: NotFound ( pair_id. clone ( ) ) ,
49
+ InfraError :: InvalidTimeStamp => EntryError :: InvalidTimestamp ,
50
50
} ) ?;
51
51
52
52
// Error if no entries found
@@ -59,6 +59,7 @@ pub async fn get_entry(
59
59
. map_err ( |db_error| match db_error {
60
60
InfraError :: InternalServerError => EntryError :: InternalServerError ,
61
61
InfraError :: NotFound => EntryError :: NotFound ( pair_id. clone ( ) ) ,
62
+ InfraError :: InvalidTimeStamp => EntryError :: InvalidTimestamp ,
62
63
} ) ?;
63
64
64
65
Ok ( Json ( adapt_entry_to_entry_response (
@@ -79,7 +80,13 @@ fn adapt_entry_to_entry_response(
79
80
pair_id,
80
81
timestamp : timestamp. timestamp_millis ( ) as u64 ,
81
82
num_sources_aggregated : entries. len ( ) ,
82
- price : format ! ( "0x{}" , price. to_bigint( ) . unwrap( ) . to_str_radix( 16 ) ) ,
83
+ price : format ! (
84
+ "0x{}" ,
85
+ price
86
+ . to_bigint( )
87
+ . unwrap_or( BigInt :: default ( ) )
88
+ . to_str_radix( 16 )
89
+ ) ,
83
90
decimals,
84
91
}
85
92
}
0 commit comments