Skip to content

Commit f63fbbc

Browse files
authored
Merge 6b62413 into b9be9f1
2 parents b9be9f1 + 6b62413 commit f63fbbc

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

firebase-functions/src/androidTest/java/com/google/firebase/functions/StreamTests.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ class StreamTests {
143143
assertThat(subscriber.throwable).isInstanceOf(FirebaseFunctionsException::class.java)
144144
}
145145

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+
146166
@Test
147167
fun genStreamWeather_receivesWeatherForecasts() = runBlocking {
148168
val inputData = listOf(mapOf("name" to "Toronto"), mapOf("name" to "London"))

firebase-functions/src/main/java/com/google/firebase/functions/PublisherStream.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,12 @@ internal class PublisherStream(
300300
val errorMessage: String
301301
if (response.code() == 404 && response.header("Content-Type") == htmlContentType) {
302302
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+
)
307309
)
308310
}
309311

@@ -313,16 +315,17 @@ internal class PublisherStream(
313315
val json = JSONObject(text)
314316
error = serializer.decode(json.opt("error"))
315317
} 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+
)
320324
)
325+
return
321326
}
322-
throw FirebaseFunctionsException(
323-
error.toString(),
324-
FirebaseFunctionsException.Code.INTERNAL,
325-
error
327+
notifyError(
328+
FirebaseFunctionsException(error.toString(), FirebaseFunctionsException.Code.INTERNAL, error)
326329
)
327330
}
328331
}

0 commit comments

Comments
 (0)