@@ -170,7 +170,23 @@ async def stromer_get_code(self) -> None:
170170 url , data = data , headers = {"Referer" : url }, allow_redirects = False
171171 )
172172 next_loc = res .headers .get ("Location" )
173+ if not next_loc :
174+ LOGGER .debug ("No next location returned from Stromer API. Full response details:" )
175+ LOGGER .debug (" **DONT DOX BY SHARING** Full Request-Data: %s" , data )
176+ LOGGER .debug (" **SHARE RESPONSIBLY ** Full Partial-Data: %s" , data ["next" ])
177+ LOGGER .debug (" Status: %s" , res .status )
178+ LOGGER .debug (" Headers: %s" , dict (res .headers ))
179+ try :
180+ body_text = await res .text ()
181+ LOGGER .debug (" Body: %s" , body_text )
182+ except Exception as err :
183+ raise NextLocationError ("Unable to provide body information from Stromer API" ) from err
184+ raise NextLocationError ("No next location returned from Stromer API" ) from None
185+
173186 next_url = f"{ self .base_url } { next_loc } "
187+ if not (next_loc .startswith ("/" ) or next_loc .startswith ("?" )):
188+ raise NextLocationError (f"Invalid next location: '{ next_loc } '. Expected start with '/' or '?'." )
189+
174190 res = await self ._websession .get (next_url , allow_redirects = False )
175191 self ._code = res .headers .get ("Location" )
176192 self ._code = self ._code .split ("=" )[1 ] # type: ignore[union-attr]
@@ -258,3 +274,6 @@ async def stromer_call_api(self, endpoint: str, full=False) -> Any:
258274
259275class ApiError (Exception ):
260276 """Error to indicate something wrong with the API."""
277+
278+ class NextLocationError (Exception ):
279+ """Error to indicate something wrong returned in next location."""
0 commit comments