File tree Expand file tree Collapse file tree 2 files changed +35
-12
lines changed
androidTest/java/com/google/firebase/functions
main/java/com/google/firebase/functions Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,26 @@ class StreamTests {
143
143
assertThat(subscriber.throwable).isInstanceOf(FirebaseFunctionsException ::class .java)
144
144
}
145
145
146
+ @Test
147
+ fun nonExistentFunction_receivesError () = runBlocking {
148
+ val function =
149
+ functions.getHttpsCallable(" nonexistentFunction" ).withTimeout(2000 , TimeUnit .MILLISECONDS )
150
+ val subscriber = StreamSubscriber ()
151
+
152
+ function.stream().subscribe(subscriber)
153
+
154
+ withTimeout(2000 ) {
155
+ while (subscriber.throwable == null ) {
156
+ delay(100 )
157
+ }
158
+ }
159
+
160
+ assertThat(subscriber.throwable).isNotNull()
161
+ assertThat(subscriber.throwable).isInstanceOf(FirebaseFunctionsException ::class .java)
162
+ assertThat((subscriber.throwable as FirebaseFunctionsException ).code)
163
+ .isEqualTo(FirebaseFunctionsException .Code .NOT_FOUND )
164
+ }
165
+
146
166
@Test
147
167
fun genStreamWeather_receivesWeatherForecasts () = runBlocking {
148
168
val inputData = listOf (mapOf (" name" to " Toronto" ), mapOf (" name" to " London" ))
Original file line number Diff line number Diff line change @@ -300,10 +300,12 @@ internal class PublisherStream(
300
300
val errorMessage: String
301
301
if (response.code() == 404 && response.header(" Content-Type" ) == htmlContentType) {
302
302
errorMessage = """ URL not found. Raw response: ${response.body()?.string()} """ .trimMargin()
303
- throw FirebaseFunctionsException (
304
- errorMessage,
305
- FirebaseFunctionsException .Code .fromHttpStatus(response.code()),
306
- null
303
+ notifyError(
304
+ FirebaseFunctionsException (
305
+ errorMessage,
306
+ FirebaseFunctionsException .Code .fromHttpStatus(response.code()),
307
+ null
308
+ )
307
309
)
308
310
}
309
311
@@ -313,16 +315,17 @@ internal class PublisherStream(
313
315
val json = JSONObject (text)
314
316
error = serializer.decode(json.opt(" error" ))
315
317
} catch (e: Throwable ) {
316
- throw FirebaseFunctionsException (
317
- " ${e.message} Unexpected Response:\n $text " ,
318
- FirebaseFunctionsException .Code .INTERNAL ,
319
- e
318
+ notifyError(
319
+ FirebaseFunctionsException (
320
+ " ${e.message} Unexpected Response:\n $text " ,
321
+ FirebaseFunctionsException .Code .INTERNAL ,
322
+ e
323
+ )
320
324
)
325
+ return
321
326
}
322
- throw FirebaseFunctionsException (
323
- error.toString(),
324
- FirebaseFunctionsException .Code .INTERNAL ,
325
- error
327
+ notifyError(
328
+ FirebaseFunctionsException (error.toString(), FirebaseFunctionsException .Code .INTERNAL , error)
326
329
)
327
330
}
328
331
}
You can’t perform that action at this time.
0 commit comments