I am encountering an issue with the code I have which involves sending data to Firebase, waiting for a response, and then displaying the result to the user:
sendRequest (data): Observable<any> {
// Sending data to Firebase
const key = this.db.list("Requests").push(data).key
return this.db.object(`Requests/${key}`).valueChanges().pipe(
timeout(30000),
skipWhile(request => !request["response"]), // Waiting for either response or timeout
take(1) // Stop once a response is received
)
}
sendOrderRequest(data): Observable<string> {
return this.sendRequest(data).pipe(
map(response => {
// Operations to be performed on success
}),
catchError(error => {
if (error.name === "TimeoutError") {
return "Request timed out."
} else {
return "An unknown error occurred."
}
})
)
}
confirmSubmit () {
this.sendOrderRequest(this.data).subscribe(result => {
console.log(result)
this.result = result
}
}
The issue is not with the timeout, but rather when the timeout error occurs. The console is displaying each letter of the error message one-by-one:
R
e
q
(etc.)
Additionally, the data binding in the HTML (this.result
) only shows the final period. What could be causing this issue?