title: Why is google bigquery api returning a 400 instead of a 500 status code?
body: <p>Why is the following google bigquery api call a 400 "Bad Request" instead of a 500 (or more specifically a 503)?  I typically wouldn't retry a 400, because it implies something was wrong with my request, but when I look at the description in the error message it looks like it is a temporary error on the server side.  Also, when I retried, the response was successful.</p>
  
  <pre><code>com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
  {
    "code" : 400,
    "errors" : [ {
      "domain" : "global",
      "message" : "The job encountered an error during execution. Retrying the job may solve the problem.",
      "reason" : "jobBackendError"
    } ],
    "message" : "The job encountered an error during execution. Retrying the job may solve the problem."
  }
      at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
      at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
      at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
  </code></pre>
  
  <p>I excluded the rest of the proprietary stacktrace, but the code looks like the following, where the SQL was simple like -> "select * from <code>project.ds.table</code> order by 1"</p>
  
  <pre><code>QueryRequest request = new QueryRequest().setQuery(queryString).setUseLegacySql(false).setTimeoutMs(1l);
  
  QueryResponse resp = bq.jobs().query(projectId, request)
          .execute();
  </code></pre>
  
  <p>According to Big Query Docs <a href="https://cloud.google.com/bigquery/troubleshooting-errors" rel="nofollow noreferrer">https://cloud.google.com/bigquery/troubleshooting-errors</a> and normal HTTP conventions.  I would think that it should be a 500 or 503.</p>
  
  <pre><code>backendError    500 or 503  This error returns when there is a temporary server failure such as a network connection problem or a server overload.
  </code></pre>