Google Cloud Pub/Sub node library error parsing - google-cloud-pubsub

I'm trying to handle error responses returned from the Google Cloud Pub/Sub api using their node client library. From what I can see, if you use their REST API directly (ie. not through the client library) they return common HTTP error codes:
https://cloud.google.com/pubsub/docs/reference/error-codes
However, their client library returns RPC style errors that do not adhere to http status code conventions.
I have a worker that is processing these responses and is expecting responses to conform to standard http response conventions. Does anyone know if there is a way to intercept the actual HTTP response that the client is handling and extract a status code from it? Alternatively, is there documentation somewhere listing out the potential RPC errors the node client can return so I can set up a mapping from them to http codes?
Thanks!

FYI this got answered as a Github issue here: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/2761#issuecomment-348358474

Related

Apache flink external api call

Is it possible to call an external api (RESTful) inside apache flink code. If it is possible then how we can do that.
I am calling an api from simple java code, it is working fine but when i use the same code in apache flink, it throws an exception :
java.io.IOException: Server returned HTTP response code: 500 for URL: http://example.com/someapi
Is it possible to call an external api (RESTful) inside apache flink code. If it is possible then how we can do that.
You can use the Async I/O feature provided in Flink Streaming API. Flinkā€™s Async I/O API allows users to use asynchronous request clients with data streams. More details and examples here.
java.io.IOException: Server returned HTTP response code: 500 for URL: http://example.com/someapi
This seems to non-flink error since the response is 500. Check the request headers/parameters that is being sent and verify if the http request is being properly created. Try some utilities like PostMan to test the API first.

Why is CORS Disabled by Default?

Alright, first of all, I am absolutely aware that we have a bunch of answers on this and there is a plethora of articles on the topic. I just read these answers a second before typing this:
Why is CORS without credentials forbidden?.
Is CORS considered bad practice?
Etc. My particular situation is this - I just set up WebAPI2 for my practice project, the front end for which is running via gulp browser-sync. I have no idea how these ports get picked, but lets say the Web API is running on port http://localhost:1234/ and browser-sync generates the website on http://localhost:4321/. So I hit the API via angular's $http and get the famous CORS error (API controller method does get hit), so I am guessing it's the API returning not allowed. Edit: I fixed this via installing a CORS for Web API package via NuGet (Article Here) before asking this Q, just referencing for anyone who might need it later.
So, I was thinking, if I deployed this, ANY request would get denied, unless I am missing something. Or would it not be denied because of something I don't understand? Is disallowing CORS just a throwback from the MVC days? Or is there some purpose to it with APIs?
Maybe I am just ranting, but this confuses the **** out of me.
CORS is based on the response headers returned from the API. It is not the API that rejects responding to the request, the web browser explicitly disallows handling the response. The API will process the request as normal.
When dealing with anything other than a GET, CORS also requires a "preflight" request to the API first, to ensure subsequent requests are allowed. This amongst sending the headers back is what the Web API nuget package provides.
CORS is off by default for security purposes.

Custom HTTP status codes from AppEngine Java endpoints

Everyone loves REST-fulness, so I'd like to return the most appropriate HTTP status codes from my AppEngine endpoints. Like 201 CREATED, for example, when a resource has been created.
But I can't find how to do this with GAE Java endpoints.
Some 4xx codes are supported by throwing an exception (NotFoundException causes a 404, for example), but that's not an appropriate solution for 2xx codes.
Can anyone help please?
Matthew
Cloud Endpoints does support creating your own Custom Exception classes by subclassing com.google.api.server.spi.ServiceException
However, from the documentation at https://developers.google.com/appengine/docs/java/endpoints/exceptions , it is mentioned that HTTP 2xx codes should not be used in custom exception classes.

How to parse HTTP requests from a C based web server

I have a programming project where I have to create a multithreaded web server which handles HTTP requests.
I just learned socket programming and I got a client and a server running. I wanted to know what the best method would be for parsing the HTTP request headers. I saw this: how to parse http request in c++ a few minutes back. But I would rather not shift to C++ at this point. So how should one go about parsing an HTTP request in C?
You can have a look at the web servers in C such as mongoose (https://github.com/cesanta/mongoose/blob/master/mongoose.c) and could use the same methodology to parse the http request. But what would I suggest is that just go through the HTTP RFC 2616 since that would help you in writing your own parser for http requests.
By the way which kind of HTTP requests your Server is handling (GET or POST or BOTH) ??
In http post requests the HTTP header & data are separated by "\r\n\r\n".
In received data sscanf the Content-Length form the http header then start reading the data after you get "\r\n\r\n" until you get the same amount of data as mentioned in Content-Length.

Force.com callout: Is there a way to get the full response from the target server

When calling a web service from Force.com, I am getting:
System.CalloutException: Web service callout failed: Unexpected
element. Parser was expecting element
'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
The network guys at the other end has asked to see the full response that Salesforce is getting from their server.
Is there a way to achieve that? I have tried running with debug level 'Finest' from execute anonymous, but that yields the same little message with no further detail.
The message you are getting is because an error is generated as Saleforce is trying to parse the response is and it isn't logged unfortunately.
The parsing error is happening because instead of a SOAP message response you are getting an HTML page. This usually happens when you are accessing a service that is protected behind a firewall. Which means you may be able to see the service when browsing on your computer but remember that Salesforce is outside of your firewall and thus any communication by Salesforce to your service will be blocked.
Couple of ways to address this but this wiki topic from Salesforce best covers the options:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_om_outboundmessaging_security.htm
The above is specific to outbound messaging but essentially the technology issues are the same.
Don't forget that Apex includes an HttpRequest Class that works as a lower layer than the SOAP APIs. You should be able to write up a test method that sends a hard-coded XML request to the server and dumps the HttpResponse so you can see it.
Adding my own best answer, based on some internet research:
You can use an external tool like Runscope as a webservice proxy to automatically forward requests and pass through responses and view the XML SOAP messages. This is not a native solution on SFDC but it does do the job.
https://www.runscope.com/
The issue is that Force.com is trying to parse a SOAP response that's actually just HTML. This happens sometimes when an error occurred server-side and the response is meant for a browser to display, rather than sending back an exception report via a properly formatted SOAP response.
If they can't figure out why they are not sending back a consumable SOAP response, then you can try using other tools (outside of Force.com) to make the same webservice call from your browser and then see what the HTML actually says on return.

Resources