@@ -37,6 +37,25 @@ pub enum IndexerServiceError {
3737 EscrowAccount ( #[ from] EscrowAccountsError ) ,
3838}
3939
40+ // Helper struct to properly format
41+ // error messages
42+ #[ derive( Serialize ) ]
43+ struct ErrorResponse {
44+ message : String ,
45+ }
46+
47+ impl ErrorResponse {
48+ fn new ( message : impl ToString ) -> Self {
49+ Self {
50+ message : message. to_string ( ) ,
51+ }
52+ }
53+
54+ fn into_response ( self , status_code : StatusCode ) -> Response {
55+ ( status_code, Json ( self ) ) . into_response ( )
56+ }
57+ }
58+
4059impl StatusCodeExt for IndexerServiceError {
4160 fn status_code ( & self ) -> StatusCode {
4261 use IndexerServiceError as E ;
@@ -55,19 +74,9 @@ impl StatusCodeExt for IndexerServiceError {
5574
5675impl IntoResponse for IndexerServiceError {
5776 fn into_response ( self ) -> Response {
58- #[ derive( Serialize ) ]
59- struct ErrorResponse {
60- message : String ,
61- }
62-
63- tracing:: error!( %self , "An IndexerServiceError occoured." ) ;
64- (
65- self . status_code ( ) ,
66- Json ( ErrorResponse {
67- message : self . to_string ( ) ,
68- } ) ,
69- )
70- . into_response ( )
77+ tracing:: error!( %self , "An IndexerServiceError occurred." ) ;
78+ let status_code = self . status_code ( ) ;
79+ ErrorResponse :: new ( self ) . into_response ( status_code)
7180 }
7281}
7382
@@ -100,7 +109,9 @@ impl StatusCodeExt for SubgraphServiceError {
100109// Tell axum how to convert `SubgraphServiceError` into a response.
101110impl IntoResponse for SubgraphServiceError {
102111 fn into_response ( self ) -> Response {
103- ( self . status_code ( ) , self . to_string ( ) ) . into_response ( )
112+ tracing:: error!( %self , "An SubgraphServiceError occurred." ) ;
113+ let status_code = self . status_code ( ) ;
114+ ErrorResponse :: new ( self ) . into_response ( status_code)
104115 }
105116}
106117
0 commit comments