6262 RequestError : status .HTTP_400_BAD_REQUEST ,
6363}
6464
65- logger = logging .getLogger ("eodag.rest.server" )
65+ logger = logging .getLogger (__name__ )
6666
6767
6868def exception_handler_factory (status_code : int ):
@@ -93,24 +93,14 @@ class ResponseSearchError(Exception):
9393
9494 _alias_to_field_cache : dict [str , str ] = {}
9595
96+ errors : list [SearchError ]
97+
9698 def __init__ (self , errors : list [tuple [str , Exception ]], stac_metadata_model : type [BaseModel ]) -> None :
9799 """Initialize error response class."""
98100 self ._errors = errors
99101 self ._stac_medatata_model = stac_metadata_model
100102
101- def _eodag_to_stac (self , value : str ) -> str :
102- """Convert EODAG name to STAC."""
103- if not self ._alias_to_field_cache :
104- self ._alias_to_field_cache = {
105- field .alias or str (field .validation_alias ): name
106- for name , field in self ._stac_medatata_model .model_fields .items ()
107- }
108- return self ._alias_to_field_cache .get (value , value )
109-
110- @property
111- def errors (self ) -> list [SearchError ]:
112- """Return errors."""
113- errors : list [SearchError ] = []
103+ self .errors = []
114104 for name , exc in self ._errors :
115105 error : SearchError = {
116106 "provider" : name ,
@@ -135,14 +125,21 @@ def errors(self) -> list[SearchError]:
135125 stac_param = self ._eodag_to_stac (error_param )
136126 error ["message" ] = error ["message" ].replace (error_param , stac_param )
137127
138- errors .append (error )
128+ self . errors .append (error )
139129
140- return errors
130+ def _eodag_to_stac (self , value : str ) -> str :
131+ """Convert EODAG name to STAC."""
132+ if not self ._alias_to_field_cache :
133+ self ._alias_to_field_cache = {
134+ field .alias or str (field .validation_alias ): name
135+ for name , field in self ._stac_medatata_model .model_fields .items ()
136+ }
137+ return self ._alias_to_field_cache .get (value , value )
141138
142139 @property
143140 def status_code (self ) -> int :
144141 """Get global errors status code."""
145- if len (self ._errors ) == 1 :
142+ if len (self .errors ) == 1 :
146143 return self .errors [0 ]["status_code" ]
147144
148145 return 400
0 commit comments