firebase / friendlyeats-web

Apache License 2.0
493 stars 412 forks source link

Clicking on Add Mock Ratings shows 400 error responses #25

Closed rodrigomata closed 6 years ago

rodrigomata commented 6 years ago

Error:

Clicking on Add Mock Ratings shows 400 error responses

screen shot 2018-07-11 at 5 19 14 pm

Response: { "error": { "code": 400, "message": "the stored version (1531347069149658) does not match the required base version (1531346493121653)", "status": "FAILED_PRECONDITION" } }

Image:

screen shot 2018-07-11 at 5 17 28 pm

Steps to reproduce:

  1. Complete codelab
  2. Click on a restaurant
  3. Click on Mock Review

EDIT: It only happens when more than 1 review is mocked

axis80 commented 6 years ago

I have a related Stack Overflow issue here: https://stackoverflow.com/questions/51814139/firestore-transaction-produces-console-error-failed-precondition-the-stored-ve . Hopefully a solution on either this issue or that question will lead to a solution on the other one.

nicolasgarnier commented 6 years ago

What you are experiencing here is how Transactions work in Firestore: one of the transactions failed to write because the data has changed in the mean time, in this case Firestore re-runs the transaction again, until it succeeds. In the case of multiple Reviews being written at the same time some of them might need to be ran again after the first transaction because the data has changed. This is expected behavior and these errors should be taken more as warnings.

Metsuryu commented 1 year ago

@nicolasgarnier is there a way to catch the error and handle it silently, instead of always printing it to the console? I tried using .catch on the promise, and wrapping everything into a try-catch, but it still always prints the 400 error to the console.