-
Notifications
You must be signed in to change notification settings - Fork 615
FIS error handling #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIS error handling #911
Conversation
…Token() calls are triggered simultaneously.
* Fixing FISClient to correctly parse expiration timestamp.
* Updating getAuthToken to return creation timestamp along with auth token and expiration timestamp.
* Propagating the exceptions to the clients. * Adding javadocs for StateListener class.
* Addressing Rayo's comment: Rename PersistedFidEntry to (#899)
…errors 2. Store detailed 4xx server exceptions in the local storage. In the succeeding getId calls,return these exceptions to the clients
Regarding the PR's description: I am confused by this sentence. |
@@ -291,6 +292,31 @@ public void testGetId_PersistedInstallationOk_BackendError() throws Exception { | |||
assertThat(updatedInstallationEntry).hasRegistrationStatus(RegistrationStatus.REGISTER_ERROR); | |||
} | |||
|
|||
@Test | |||
public void testGetId_500ServerError_UnregisteredFID() throws Exception { | |||
when(backendClientReturnsOk.createFirebaseInstallation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does this test stub a 500 error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion. Added a comment & changed the test name. Does this makes sense?
@@ -41,6 +41,9 @@ | |||
|
|||
public abstract long getTokenCreationEpochInSecs(); | |||
|
|||
@Nullable | |||
public abstract String getFISException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we exposing this to clients? Having exception == String is weird. How about just calling it error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the stored error message. Changed it. PTAL.
Idea: getId is non-blocking call. After we return the id, we encounter some error during registration. We persist the error message & return it to the clients next time getId is called.
firebase-installations/api.txt
Outdated
@@ -44,6 +44,7 @@ package com.google.firebase.installations.local { | |||
method @NonNull public static com.google.firebase.installations.local.PersistedInstallationEntry.Builder builder(); | |||
method @Nullable public abstract String getAuthToken(); | |||
method public abstract long getExpiresInSecs(); | |||
method @Nullable public abstract String getFISException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be #getFisException
Compare:
http://go/java-style#s5.3-camel-case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.thanks.
.setExpiresInSecs(installationResponse.getAuthToken().getTokenExpirationTimestamp()) | ||
.setTokenCreationEpochInSecs(creationTime) | ||
.build()); | ||
if (installationResponse.getFid() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi:
If a #createInstallation request gets a successful response, the field "fid" should always be set.
What happens here if the field "fid" is not set? What state will the SDK end up in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to differentiate between 200, 5xx & 4xx errors.
200 - createInstallation successful response - fid is not empty
5xx - retry once - empty response & fid
4xx - throws exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is what you are doing, then I would recommend your code to express that.
In this case, I would recommend that you check for the 200 HTTP-status instead of the "fid" field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that: I have to include Response Code as a field in InstallationResponse. Is that what you recommend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since y'all control both sides of this exchange we should be able to use and trust the status codes. imo having canonical status codes as a classification for installation responses is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. PTAL.
@@ -90,6 +93,9 @@ public abstract Builder setRegistrationStatus( | |||
@NonNull | |||
public abstract Builder setTokenCreationEpochInSecs(long value); | |||
|
|||
@NonNull | |||
public abstract Builder setFISException(@Nullable String value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can this be @nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When PersistedInstallationEntry stores a successfully registered entry.
@@ -128,7 +128,8 @@ public InstallationResponse createFirebaseInstallation( | |||
throw new FirebaseException(readErrorResponse(httpsURLConnection)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
referring to the 4 lines above:
case 500: retryCount++;
Is it possible for us to treat all server-errors (i.e. 5XX) like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. PTAL.
Background: After our discussion: On 5xx, we retry once & leave the persisted installation entry status as UNREGISTERED. As a result, no exception will be thrown on subsequent getId calls. |
.setExpiresInSecs(installationResponse.getAuthToken().getTokenExpirationTimestamp()) | ||
.setTokenCreationEpochInSecs(creationTime) | ||
.build()); | ||
if (installationResponse.getFid() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is what you are doing, then I would recommend your code to express that.
In this case, I would recommend that you check for the 200 HTTP-status instead of the "fid" field.
For FirebaseInstallationServiceClient#createFirebaseInstallation