Google Bigquery Backend Error with streaming inserts but not display in console - google-bigquery

I am getting following error from Google bigquer while doing streaming inserts:
Error message Signet::AuthorizationError: Unexpected status code: 500. Server message: { "error": "internal_failure" }
I can understand that there can few errors but the same doesn't get reflected on console as shown below:
As you can see in above, image, there are no 500 errors but yet in real there were 10 500 internal_failure errors.
Can you tell me why these errors don't refect on console & how do I ensure they don't happen?

This looks like a failiure to get your authentication token. This failure would occur before the client code even attempts to call the bigquery api, so the console you are looking at is accurately representing traffic.
I suspect it is a failure on a request to https://accounts.google.com/o/oauth2/token. Perhaps monitoring on outgoing http requests could verify this? (For example, see Getting error 500 when trying to obtain access token from authorization code and Internal_failure while getting refreshtoken using code?)
Back to the BigQuery API: when it returns an http error code 500, the error string will be one of "backendError" or "internalError". (For the curious: "backendError" is usually retriable, while "internalError" is likely a permanent failure.)

Related

How can a Slack app communicate to the user why a slash command failed, and let the user edit the command?

When an app fails to handle a Slack slash command, the text is brought back to allow the user to edit it and immediately send it again. I have a slash-command that searches, but might fail to find any results. In that case, I would like the user to immediately be able to modify their search. The Slack docs explain that I should always return a 200 HTTP status, but then Slack also erases the command and the user can't immediately try again. When I tried to respond with a 404 status, the users get an alarming message like failed with the error "http_client_error". Is there a way to fail but also provide a custom message to the user why?
Yes, but you must not use HTTP status codes to community a failed search.
Just always return HTTP OK 200 and then add a response message telling the user what went wrong. You can do that by directly replying to the request from Slack within 3 seconds, or alternatively by sending a message to the response_url.
This is also clearly expressed in the offical documentation for slash commands:
Sending Error Responses
There are going to be times when you need to let the user know that something went wrong - perhaps the user supplied an incorrect text parameter alongside the command, or maybe there was a failure in an API being used to generate the command response.
It would be tempting in this case to return an HTTP 500 response to
the initial command, but this isn't the right approach. The status
code returned as a response to the command should only be used to
indicate whether or not the request URL successfully received the data
payload - while an error might have occurred in processing and
responding to that payload, the communication itself was still
successful. (Source)
As far as I know it is not possible to signal Slack that the user should be able to edit his last command though.

The reason codes from BigQueryError.getError()

Do we have a list of possible reason codes from BigQueryError.getReason() https://googleapis.github.io/google-cloud-java/google-cloud-clients/apidocs/index.html?com/google/cloud/bigquery/package-summary.html ?
BigQueryError is a java class from Google's BigQuery client lib.
We are streaming inserting rows to BigQuery. Would like to know under what kind of reason codes, we can retry the insertion.
Thanks
You can find the BigQuery error codes in the following page
https://cloud.google.com/bigquery/troubleshooting-errors
One important point for HTTP errors from the documentation (not listed in the doc)
If you receive an HTTP response code that doesn't appear in the list
below, the response code indicates an issue or an expected result with
the HTTP request. For example, a 502 error indicates there is an issue
with your network connection. For a full list of HTTP response codes,
see HTTP response codes.

HTTP Code for payment accepted/refused in a REST API

In a REST API, in payment method (user gives his card infos), should I return 200 if the payment fails (for card expiration or balance too low problem) with an attached message + custom additional error code in JSON ? Or is there any other HTTP code for this ?
I did not found any information about this particular case, I just found 402 code for payment but it does not seem to be designed for this case. I'm not talking about a server (500) error or unreachable bank, just payment problem due to user card.
I think you should use 406 code.
Code - 406
Message - Not Acceptable
Description - Insufficient funds or other payment problem.
What does "the payment fails" mean exactly? I can think of a few different scenarios, many of which might require a different status code to reflect the actual status.
It all depends how the rest of your API works though. If you already use JSON objects in the response body, you may as well report 200 OK for any action:
HTTP/1.1 200 OK
...
{
success: false,
message: "Balance too low"
}
If you don't want that, any 4xx or 5xx error that applies will do. Try searching.
REST HTTP status codes for failed validation or invalid duplicate
What's an appropriate HTTP status code to return by a REST API service for a validation failure?
REST response code for invalid data

Fusion table api migration

I am using fusion table APIs to insert/update data in my table. Last week I migrated my API to new version v1 as referred in this sample. But now, when I run the code, the following error displayed.
400 Bad Request
{
"error" : "unauthorized_client"
}
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "unauthorized_client"
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:303)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:323)
at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:607)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:526)
at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:287)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:836)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
at com.prasanna.survey.pushapis.FusionPush.insertData(FusionPush.java:198)
at com.prasanna.survey.pushapis.FusionPush.main(FusionPush.java:96)
Java Result: 1
How to debug this error?
This error typically occurs if you change the client_id of an application.
The reason is, you already have an access token for the Fusion API that's based on the old client_id. When you request a refresh token (as you can see is happening in the stack trace) with the new client_id, you get that very unhelpful error message.
The easiest way to handle this is to clear the existing credential from the system so it has to receive a clean access token. You can do this programatically with the Google API Java Client, or you can just remove the file from your system. On my Ubuntu machine, it is located at ~/.credentials/<api-name>.json.

Which Http Status code to return when user provided data fails validation in Web Service?

When the user enters data and submits that data, we pass it to the server using and XMLHttpRequest. But, if that data fails validation, we have to return a 400 level status code. I thought the appropriate code would be 403. However, my colleague doesn't agree but doesn't know which to use.
Which one would you use?
Thanks!
400 would be more correct, i.e. the request contained invalid data. 403 would imply some kind of permisions error, i.e. the request was well formed and correct but the action was not allowed. If i was writing code to consume a web service and i got a 403 error it would never occur to me that it was because i was sending invalid data, it would be very confusing indeed.