You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(functions): use notifyError() instead of throwing (#6773)
Throwing inside the `PublisherStream` causes a Runtime exception that
can't be caught in the call site.
Instead, we should use `notifyError()` so that the error can be caught
in the `Subscriber#onError()` function.
I tried to catch the exception using both of the code snippets below,
but none of them worked. (they both work with the changes in this PR):
```kotlin
functions.getHttpsCallable("nonExistentFunction")
.stream().asFlow()
.catch {
// Handle error for a 404 function
}
.collect {
// ...
}
```
```kotlin
try {
functions.getHttpsCallable("nonExistentFunction")
.stream().asFlow()
.collect {
// ...
}
} catch(e: Exception) {
// Handle error for a 404 function
}
```
Runtime exception thrown:
```
FATAL EXCEPTION: OkHttp Dispatcher
Process: com.google.samples.quickstart.functions, PID: 13321
com.google.firebase.functions.FirebaseFunctionsException: Value <html><head> of type java.lang.String cannot be converted to JSONObject Unexpected Response:
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Page not found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Page not found</h1>
<h2>The requested URL was not found on this server.</h2>
<h2></h2>
</body></html>
at com.google.firebase.functions.PublisherStream.validateResponse(PublisherStream.kt:316)
at com.google.firebase.functions.PublisherStream.access$validateResponse(PublisherStream.kt:41)
at com.google.firebase.functions.PublisherStream$startStreaming$1$4.onResponse(PublisherStream.kt:161)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651)
at java.lang.Thread.run(Thread.java:1119)
```
0 commit comments