Skip to content

Commit

Permalink
Downgrade logging from severe to info for attributed errors that do n…
Browse files Browse the repository at this point in the history
…ot require developer action or investigation (#966)
  • Loading branch information
ayushagarwalfb authored Mar 3, 2021
1 parent 0f4485f commit 995efca
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 101 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@

import com.restfb.exception.FacebookOAuthException;
import org.datatransferproject.spi.transfer.types.CopyExceptionWithFailureReason;
import org.datatransferproject.transfer.facebook.exceptions.FacebookSessionInvalidatedException;
import org.datatransferproject.transfer.facebook.exceptions.FacebookUnconfirmedUserException;
import org.datatransferproject.transfer.facebook.exceptions.FacebookUserCheckpointedException;
import org.datatransferproject.spi.transfer.types.SessionInvalidatedException;
import org.datatransferproject.spi.transfer.types.UnconfirmedUserException;
import org.datatransferproject.spi.transfer.types.UserCheckpointedException;

public class FacebookTransferUtils {

public static FacebookOAuthException handleFacebookOAuthException(FacebookOAuthException e)
throws CopyExceptionWithFailureReason {
String message = e.getMessage();
if (message != null && message.contains("the user is not a confirmed user")) {
throw new FacebookUnconfirmedUserException(
throw new UnconfirmedUserException(
"The user account is not confirmed or deactivated", e);
} else if (message != null && message.contains("code 190, subcode 459")) {
// Throw out exception for known user checkpointed error from Graph API
throw new FacebookUserCheckpointedException("The user has been checkpointed", e);
throw new UserCheckpointedException("The user has been checkpointed", e);
} else if (message != null && message.contains("code 190, subcode 460")) {
throw new FacebookSessionInvalidatedException("The user session has been invalidated", e);
throw new SessionInvalidatedException("The user session has been invalidated", e);
} else if (message != null && message.contains("code 190, subcode 463")) {
throw new FacebookSessionInvalidatedException("The user session has expired", e);
throw new SessionInvalidatedException("The user session has expired", e);
} else {
return e;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.datatransferproject.spi.transfer.types;

public enum FailureReasons {
CREDS_TIMEOUT("CREDS_TIMEOUT"),
DESTINATION_FULL("DESTINATION_FULL"),
INVALID_TOKEN("INVALID_TOKEN"),
PERMISSION_DENIED("PERMISSION_DENIED"),
CREDS_TIMEOUT("CREDS_TIMEOUT"),
UPLOAD_ERROR("UPLOAD_ERROR");
SESSION_INVALIDATED("SESSION_INVALIDATED"),
UNCONFIRMED_USER("UNCONFIRMED_USER"),
UPLOAD_ERROR("UPLOAD_ERROR"),
USER_CHECKPOINTED("USER_CHECKPOINTED");

private final String string;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.datatransferproject.spi.transfer.types;

import javax.annotation.Nonnull;

public class SessionInvalidatedException extends CopyExceptionWithFailureReason {

public SessionInvalidatedException(String message, Throwable cause) {
super(message, cause);
}

@Nonnull
@Override
public String getFailureReason() {
return FailureReasons.SESSION_INVALIDATED.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.datatransferproject.spi.transfer.types;

import javax.annotation.Nonnull;

public class UnconfirmedUserException extends CopyExceptionWithFailureReason {

public UnconfirmedUserException(String message, Throwable cause) {
super(message, cause);
}

@Nonnull
@Override
public String getFailureReason() {
return FailureReasons.UNCONFIRMED_USER.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.datatransferproject.spi.transfer.types;

import javax.annotation.Nonnull;

public class UserCheckpointedException extends CopyExceptionWithFailureReason {

public UserCheckpointedException(String message, Throwable cause) {
super(message, cause);
}

@Nonnull
@Override
public String getFailureReason() {
return FailureReasons.USER_CHECKPOINTED.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.datatransferproject.spi.transfer.security.AuthDataDecryptService;
import org.datatransferproject.spi.transfer.types.CopyException;
import org.datatransferproject.spi.transfer.types.CopyExceptionWithFailureReason;
import org.datatransferproject.spi.transfer.types.FailureReasons;
import org.datatransferproject.transfer.copier.InMemoryDataCopier;
import org.datatransferproject.types.common.ExportInformation;
import org.datatransferproject.types.transfer.auth.AuthData;
Expand Down Expand Up @@ -131,14 +132,24 @@ void processJob() {
() -> format("Finished copy for jobId: %s with %d error(s).", jobId, numErrors));
success = errors.isEmpty();
} catch (CopyExceptionWithFailureReason e) {
monitor.severe(
() ->
format(
"Error with failure code '%s' while processing jobId: %s",
e.getFailureReason(), jobId),
e,
EventCode.WORKER_JOB_ERRORED);
addFailureReasonToJob(jobId, e.getFailureReason());
String failureReason = e.getFailureReason();
if (failureReason.contains(FailureReasons.DESTINATION_FULL.toString())) {
monitor.info(() -> "The remaining storage in the user's account is not enough to perform this operation.", e);
} else if (failureReason.contains(FailureReasons.INVALID_TOKEN.toString()) ||
failureReason.contains(FailureReasons.SESSION_INVALIDATED.toString()) ||
failureReason.contains(FailureReasons.UNCONFIRMED_USER.toString()) ||
failureReason.contains(FailureReasons.USER_CHECKPOINTED.toString())) {
monitor.info(() -> "Got token error", e);
} else {
monitor.severe(
() ->
format(
"Error with failure code '%s' while processing jobId: %s",
failureReason, jobId),
e,
EventCode.WORKER_JOB_ERRORED);
}
addFailureReasonToJob(jobId, failureReason);
} catch (IOException | CopyException | RuntimeException e) {
monitor.severe(() -> "Error processing jobId: " + jobId, e, EventCode.WORKER_JOB_ERRORED);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.datatransferproject.transfer.copier;

import static java.lang.String.format;

import com.google.common.base.Stopwatch;
import com.google.inject.Provider;
import java.io.IOException;
Expand Down Expand Up @@ -161,7 +159,6 @@ protected ExportResult<?> copyIteration(
}
}
} catch (RetryException | RuntimeException e) {
monitor.severe(() -> "Got error importing data", e);
if (e.getClass() == RetryException.class
&& CopyExceptionWithFailureReason.class.isAssignableFrom(e.getCause().getClass())) {
throw (CopyExceptionWithFailureReason) e.getCause();
Expand Down

0 comments on commit 995efca

Please sign in to comment.