Java Code Examples for com.google.api.client.http.HttpStatusCodes#STATUS_CODE_BAD_REQUEST

The following examples show how to use com.google.api.client.http.HttpStatusCodes#STATUS_CODE_BAD_REQUEST . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3Service.java    From modeldb with Apache License 2.0 6 votes vote down vote up
@Override
public void commitMultipart(String s3Key, String uploadId, List<PartETag> partETags)
    throws ModelDBException {
  // Validate bucket
  Boolean exist = doesBucketExist(bucketName);
  if (!exist) {
    throw new ModelDBException("Bucket does not exists", io.grpc.Status.Code.INTERNAL);
  }
  CompleteMultipartUploadRequest completeMultipartUploadRequest =
      new CompleteMultipartUploadRequest(bucketName, s3Key, uploadId, partETags);
  try {
    CompleteMultipartUploadResult result =
        s3Client.completeMultipartUpload(completeMultipartUploadRequest);
    LOGGER.info("upload result: {}", result);
  } catch (AmazonS3Exception e) {
    if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_BAD_REQUEST) {
      LOGGER.info("message: {} additional details: {}", e.getMessage(), e.getAdditionalDetails());
      throw new ModelDBException(e.getErrorMessage(), io.grpc.Status.Code.FAILED_PRECONDITION);
    }
    throw e;
  }
}
 
Example 2
Source File: EmailAccount.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Triggers the authentication process for the associated {@code username}.
 */
public void getUserAuthenticated() throws IOException {
    // assume user is authenticated before
    service = new GmailServiceMaker(username).makeGmailService();

    while (true) {
        try {
            // touch one API endpoint to check authentication
            getListOfUnreadEmailOfUser();
            break;
        } catch (HttpResponseException e) {
            if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_FORBIDDEN
                    || e.getStatusCode() == HttpStatusCodes.STATUS_CODE_UNAUTHORIZED
                    || e.getStatusCode() == HttpStatusCodes.STATUS_CODE_BAD_REQUEST) {
                System.out.println(e.getMessage());
                // existing credential missing or not working, should do authentication for the account again
                service = new GmailServiceMaker(username, true).makeGmailService();
            } else {
                throw new IOException(e);
            }
        }
    }
}
 
Example 3
Source File: SessionLinksRecoveryAction.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ActionResult execute() {
    String recoveryEmailAddress = getNonNullRequestParamValue(Const.ParamsNames.SESSION_LINKS_RECOVERY_EMAIL);

    if (!StringHelper.isMatching(recoveryEmailAddress, REGEX_EMAIL)) {
        return new JsonResult("Invalid email address: " + recoveryEmailAddress,
                                HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
    }

    String userCaptchaResponse = getRequestParamValue(Const.ParamsNames.USER_CAPTCHA_RESPONSE);
    if (!recaptchaVerifier.isVerificationSuccessful(userCaptchaResponse)) {
        return new JsonResult(new SessionLinksRecoveryResponseData(false, "Something went wrong with "
                + "the reCAPTCHA verification. Please try again."));
    }

    EmailWrapper email = emailGenerator.generateSessionLinksRecoveryEmailForStudent(recoveryEmailAddress);
    EmailSendingStatus status = emailSender.sendEmail(email);

    if (status.isSuccess()) {
        return new JsonResult(new SessionLinksRecoveryResponseData(true,
                "The recovery links for your feedback sessions have been sent to the "
                        + "specified email address: " + recoveryEmailAddress));
    } else {
        return new JsonResult(new SessionLinksRecoveryResponseData(false, "An error occurred. "
                + "The email could not be sent."));
    }
}
 
Example 4
Source File: ApiErrorExtractor.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the given exception indicates that 'userProject' is missing in request.
 * Recursively checks getCause() if outer exception isn't an instance of the correct class.
 */
public boolean userProjectMissing(IOException e) {
  GoogleJsonError jsonError = getJsonError(e);
  return jsonError != null
      && jsonError.getCode() == HttpStatusCodes.STATUS_CODE_BAD_REQUEST
      && USER_PROJECT_MISSING_MESSAGE.equals(jsonError.getMessage());
}