While calling endpoint API, sometimes we are getting 500 Unknown error from server, but most of the time API works fine. And also in case of 500 Unknown error, we are unable to see any logs in google console logs.
API response takes 2 sec approx. We are using App engine Java deployment.
Can anyone help me find the root cause of this problem?
Following is the chrome console error
/conge-portal/#!/dashboard/myage:1 XMLHttpRequest cannot load https://a-master-server.appspot.com/_ah/api/ageEndPoint/v1/aghie…5648/674390454714943921958166322392772?showTarget=true&month=May&year=2017. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 500.
From the error message, it looks like browser rejected a preflight CORS OPTIONS request because "http://localhost" is not listed as the the allowed origins.
Are you using App Engine standard or App Engine Flex environment? CORS handling are different on these two platforms.
Issue stopped after migrating to endpoint framework 2.0
Related
I'm using Spring Boot to consume API. For some APIs, it works but for some others it fails returning 500 Internal Server Error. For example, when consuming this API https://quoters.apps.pcfone.io/api/random it works, but https://reqres.in/api/unknown/23 returns 500 error. To what can this be due?
My code is simple:
restTemplate.getForEntity("https://reqres.in/api/unknown/23", String.class)
A request to the error-causing URL responds with a 404 Not Found status code. Please check if the server is serving on the given endpoint.
As for the 500 Internal Server Error, what's happening is that upon receiving the 404 from the server, your RestTemplate is throwing a RestClientException, which is being converted into a response with the status code: 500. You can add explicit handling for this using #ControllerAdvice, which will allow you to have more control over the response status.
Here's a reference for ControllerAdvice in Spring: https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
I have created a web service using dropwizard.
Through this, I am able to create resources, wherein I have created an entity for indexing the document, search request, getting doc by id.
By hitting the API in postman I get the desired result.
For developing the web application I built the front end using ember.js.
But when I send a request to my application I am getting CORS policy exception.
When I am sending request through postman to http://localhost:9090 (9090 is the port number of my ApplicationConnector) then it is responding to the request.
Now when I send request from origin http://localhost:4200 (4200is the default port number for ember.js) to http://localhost:9090 it is giving error :
Access to XMLHttpRequest at http://localhost:9090/{indexName}/{id} >from origin http://localhost:4200 has been blocked by CORS policy: Response to preflight request doesn't pass access control check:
No 'Access->Control-Allow-Origin' header is present on the requested resource.
So can someone please explain how to resolve this issue and if there is any other way apart from enabling CORS in Dropwizard ?
You need to enable CORS in Dropwizard or serve both the frontend and the API from the same host (hostname and port). Otherwise it's forbidden by CORS security feature, which is enabled by default in all major browsers. Postman does not care about CORS.
I am trying to use drive Rest API in my app by following the official quickstart documentation. I generated a SHA1 key, everything works fine but when I call drive API from android phone, I get 400 bad request.
How is this caused and how can I fix this?
HTTP 400 means that the server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
Could you please take a look at your HTTP request whether it is what you intended it to be?
I wrote a context.io 2.0 java client for : accounts,discovery, threads and messages operations to be used in my project (based on the available ContextIO Java client).
My code is at : https://github.com/dileepajayakody/isis-reputationbox/blob/master/reputationbox/dom/src/main/java/at/tomtasche/contextio/ContextIO_V20.java
While testing it, when I invoke the accounts request: https://api.context.io/2.0/accounts and discovery requests (eg: https://api.context.io/2.0/discovery?email=testemail#gmail.com&source_type=IMAP, I successfully get the desired response with a HTTP 200
However when I invoke the messages, threads, contacts requests by adding the account_id parameter in the request URL (eg : https://api.context.io/2.0/accounts/1234ff425ad/messages) I get an empty JSON array with a HTTP 403 Forbidden response.
When I try out the same request in the contextio developer console, I get the response without a problem.
I don't think it's something wrong with the way I sign the oauth request since it's the same way I sign for accounts and discovery requests for which I get the contextIO response properly.
Any help in resolving this error is much appreciated.
Thanks,
Dileepa
I don't think the issue is related to oauth request signing, since we normally return 401 or 404 messages for errors there.
The fact there's no body content with the 403 response leads me to believe your api_key does not own the account specified. If it did own it then we would include a json array with type, code, value parameters to help debug the issue. If you have two developer accounts then you may just be using the wrong one for this test.
I hope this helps. If not, please feel free to contact us at support#context.io.
Thanks!
Dan
while uploading images to server, it gives me expectation failed error response code 417.
My server side coding is in php, and client is android
The RFC says that this is due to an Expect request header that the server can't meet. Look at the request headers sent by your client application, and see what their purpose is and if they're necessary.
request.getParams().setBooleanParameter( "http.protocol.expect-continue", false ) worked in my case