/** A helper that generates the error JSON payload that Google APIs produce. */ private static GoogleJsonErrorContainer errorWithReasonAndStatus(String reason, int status) { ErrorInfo info = new ErrorInfo(); info.setReason(reason); info.setDomain("global"); // GoogleJsonError contains one or more ErrorInfo objects; our utiities read the first one. GoogleJsonError error = new GoogleJsonError(); error.setErrors(ImmutableList.of(info)); error.setCode(status); error.setMessage(reason); // The actual JSON response is an error container. GoogleJsonErrorContainer container = new GoogleJsonErrorContainer(); container.setError(error); return container; }
@Before public void setUp() throws Exception { accessDenied = googleJsonResponseException( HttpStatusCodes.STATUS_CODE_FORBIDDEN, "Forbidden", "Forbidden"); statusOk = googleJsonResponseException( HttpStatusCodes.STATUS_CODE_OK, "A reason", "ok"); notFound = googleJsonResponseException( HttpStatusCodes.STATUS_CODE_NOT_FOUND, "Not found", "Not found"); badRange = googleJsonResponseException( ApiErrorExtractor.STATUS_CODE_RANGE_NOT_SATISFIABLE, "Bad range", "Bad range"); alreadyExists = googleJsonResponseException( 409, "409", "409"); resourceNotReady = googleJsonResponseException( 400, ApiErrorExtractor.RESOURCE_NOT_READY_REASON_CODE, "Resource not ready"); // This works because googleJsonResponseException takes final ErrorInfo ErrorInfo errorInfo = new ErrorInfo(); errorInfo.setReason(ApiErrorExtractor.RATE_LIMITED_REASON_CODE); notRateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, ""); errorInfo.setDomain(ApiErrorExtractor.USAGE_LIMITS_DOMAIN); rateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, ""); errorInfo.setDomain(ApiErrorExtractor.GLOBAL_DOMAIN); bigqueryRateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, ""); }