@@ -82,6 +82,15 @@ class WillhabenAPIImpl(private val httpClient: HttpClient) : WillhabenAPI, KoinC
8282
8383 logger.debug { " Redirected to $newUrl " }
8484 mappedUrl = newUrl
85+ } catch (ex: ClientRequestException ) {
86+ when (ex.response.status) {
87+ HttpStatusCode .NotFound , HttpStatusCode .Gone -> {
88+ logger.warn { " Listing $url is expired" }
89+ return null
90+ }
91+ HttpStatusCode .Forbidden -> throw WillhabenBlockedException ()
92+ else -> throw WillhabenRequestException (ex)
93+ }
8594 }
8695 }
8796
@@ -92,7 +101,14 @@ class WillhabenAPIImpl(private val httpClient: HttpClient) : WillhabenAPI, KoinC
92101 }
93102
94103 override suspend fun fetchWishlist (creds : WillhabenCredentials , cleanTitle : Boolean ): WillhabenWishlist {
95- val response = httpClient.getAuthenticated(WISHLIST_PATH , creds)
104+ val response = try {
105+ httpClient.getAuthenticated(WISHLIST_PATH , creds)
106+ } catch (ex: ClientRequestException ) {
107+ when (ex.response.status) {
108+ HttpStatusCode .Unauthorized , HttpStatusCode .Forbidden -> throw WillhabenBlockedException ()
109+ else -> throw WillhabenRequestException (ex)
110+ }
111+ }
96112
97113 val props = response.parseNextPageProps(json)
98114 val listings = props
@@ -114,7 +130,14 @@ class WillhabenAPIImpl(private val httpClient: HttpClient) : WillhabenAPI, KoinC
114130 appendEncodedPathSegments(" iad" , query)
115131 }.build()
116132
117- val response = httpClient.get(url)
133+ val response = try {
134+ httpClient.get(url)
135+ } catch (ex: ClientRequestException ) {
136+ when (ex.response.status) {
137+ HttpStatusCode .Forbidden -> throw WillhabenBlockedException ()
138+ else -> throw WillhabenRequestException (ex)
139+ }
140+ }
118141
119142 val props = response.parseNextPageProps(json)
120143 val searchResults = props
0 commit comments