2626from kiota_abstractions .method import Method
2727from kiota_abstractions .headers_collection import HeadersCollection
2828from kiota_abstractions .request_information import RequestInformation
29- from kiota_abstractions .serialization . parsable import Parsable
29+ from kiota_abstractions .serialization import Parsable , ParsableFactory
3030
3131from msgraph_core .models .page_result import PageResult # pylint: disable=no-name-in-module, import-error
3232
@@ -59,12 +59,13 @@ def __init__(
5959 self ,
6060 response : Union [T , list , object ],
6161 request_adapter : RequestAdapter ,
62- constructor_callable : Optional [Callable ] = None
62+ constructor_callable : Optional [Callable ] = None ,
63+ error_mapping : Optional [Dict [str , type [ParsableFactory ]]] = None ,
6364 ):
6465 self .request_adapter = request_adapter
6566
6667 if isinstance (response , Parsable ) and not constructor_callable :
67- parsable_factory = type (response )
68+ parsable_factory = type (response ) # type: ignore
6869 elif constructor_callable is None :
6970 parsable_factory = PageResult
7071 else :
@@ -89,6 +90,7 @@ def __init__(
8990 if page is not None :
9091 self .current_page = page
9192 self .has_next = bool (page .odata_next_link )
93+ self .error_mapping = error_mapping if error_mapping else dict ()
9294
9395 def set_headers (self , headers : dict ) -> HeadersCollection :
9496 """
@@ -100,6 +102,7 @@ def set_headers(self, headers: dict) -> HeadersCollection:
100102 header names and the values are the header values.
101103 """
102104 self .headers .add_all (** headers )
105+ return self .headers
103106
104107 @property
105108 def delta_link (self ):
@@ -181,7 +184,7 @@ def convert_to_page(response: Union[T, list, object]) -> PageResult:
181184 page : PageResult = PageResult (next_link , value )
182185 return page
183186
184- async def fetch_next_page (self ) -> List [ Parsable ]:
187+ async def fetch_next_page (self ) -> Optional [ Union [ T , PageResult ] ]:
185188 """
186189 Fetches the next page of items from the server.
187190 Returns:
@@ -202,9 +205,8 @@ async def fetch_next_page(self) -> List[Parsable]:
202205 request_info .headers = self .headers
203206 if self .request_options :
204207 request_info .add_request_options (* self .request_options )
205- error_map : Dict [str , int ] = {}
206208 response = await self .request_adapter .send_async (
207- request_info , self .parsable_factory , error_map
209+ request_info , self .parsable_factory , self . error_mapping # type: ignore
208210 )
209211 return response
210212
0 commit comments